Search code examples
apachemod-rewritemeteoriron-router

Sharing the same code between several versions of the same Meteor web


I have a Meteor web deployed with Phusion Passenger integrated with Apache. The users access it with http://mycompany.org:3001.

That Meteor web communicates, via REST API, with another external server. That external server has 3 versions of the same REST API:

Each version of the above REST API manages a different user database, i.e. user_DB_1 -> v1, user_DB_2 -> v2, user_DB_3 -> v3.

Currently, my deployed Meteor web is making calls to the v1 of that REST API (http://external_server/v1/restapi).

Now, I have to call the other versions of the REST API (v2 and v3) with the same Meteor web, like this:

Is it possible to capture the version of that URL and pass it as parameter to the Meteor web so that it calls the corresponding API? For example, if the user make HTTP requests to http://mycompany.org/meteor_web_v1/login, then the web calls to http://external_server/v1/restapi, and so on...

Which is the approach here? Using maybe Apache mod_rewrite, Iron Router or which solution?


Solution

  • You can use either flow router or iron router to give you the url part as a parameter, you name it like this in your route declaration: '/:myroute'

    and then you will get a route parameter as a variable which you can use in your code to pass to your server method to do the http request.

    You are doing the http request from the server, right ? Doing it that way prevents any CORS problems, and offloads the waiting to the server. The server should then update the database wth the received data, and the client will auto-refresh to make the results available.