Subdomain Multi-tenant App


#1

Hi there. Currently I am running a fairly complicated SaaS (Rails only) project and is due to upgrade to something bigger on front-end (+ API access) and since I have some experience with Ember it makes sense to go for it. I am at planning stage to get my head around how I would achieve functionality without many regressions for existing clients. Currently my app hosts multiple clients (using Apartment gem on Rails side) where each client gets its own subdomain, eg.:

While Sign Up is handled via signup.example.com, as you can imagine example.com runs on its own server (marketing stuff), so DNS config is literally set to redirect any URL with wildcard subdomain to Rails App, which handles log in functionality (if client exists - show login page client.example.com/login, otherwise redirect to find your account/sign up page). So my question is how would this structure look with Ember on top of all this? In theory I am thinking of any URL with Subdomain would be redirected to Ember app (starting point signup/app/whatever.example.com for non-existing accounts), while Ember App itself would talk to rails api via api.example.com/clientExample/v1/? Would this work or it has some obvious stupid mistake which I have not thought about yet? Thank you.


#2

I would just have the rails app serve the Ember app’s index.html file from redis/s3/disk.

Check out how this example works: http://ember-cli-deploy.com/docs/v0.6.x/lightning-strategy-examples/

In development, you can just grab the index.html file from the ember app’s dist folder or just make a HTTP request to the ember-cli server.

You will have to shim a few things like the livereload path and csrf tokens, but it’s a pretty trivial string replacement. Things like: String.replace("/ember-cli-live-reload.js", "http://localhost:4200/ember-cli-live-reload.js")

Let me know if that helps clear things up for you.

Cheers, Ben