Moon
Moon

Reputation: 35265

Dynamic ROOT_URL for Meteor app being served from multiple subdomains

I have an app which runs on multiple subdomain (one per tenant). Works all good in development environment since I do not set value for ROOT_URL there.

But, when I deploy an app to production, Meteor asks me to set the ROOT_URL environment variable.

I can not set the value of ROOT_URL to a specific domain in the environment variable since app runs on multiple subdomains. What would be the best way for me to set the ROOT_URL value via code?

I am open to better solutions.

Upvotes: 2

Views: 958

Answers (2)

David Weldon
David Weldon

Reputation: 64312

The variable only needs to be defined at the time the app starts, so you can easily build a multi-tenant environment by starting your application instances with a script like this:

#!/bin/bash

export PORT=3000
export ROOT_URL=https://domain1.example.com
node /path/to/your/app/bundle/main.js

export PORT=4000
export ROOT_URL=https://domain2.example.com
node /path/to/your/app/bundle/main.js

exit 0

Upvotes: 1

dubvfan87
dubvfan87

Reputation: 641

You can change environmental variables inside your code. You could do something like this.

Meteor.startup(function() {
    //do some logic...
    //...
    process.env.ROOT_URL = 'http://subdomain1.mydomain.com';
});

Edit: You could also try using the meteor cluster package which I think can do what you want. https://github.com/meteorhacks/cluster

Upvotes: 0

Related Questions