EventedMind/iron-router — pull request #795 by DanielDornhardt (2014-08-28 21:47:03+00:00)
Title: Update Router to support a ROOT_URL subdirectory, if set

Hello,

I had an requirement to allow for multiple meteor app instances on one domain name, eg

domain.com/app1/
and
domain.com/app2/

etc.

And I didn't want to add this /appX/ to every route manually, which would be especially annoying if the same app would run on multiple different subdirectories.

So I patched this into the IronRouter like this:

If there's a route being dispatched on the client, and if the app is running in a URL-Subdirectory on the domain, configured via ROOT_URL on the server, then the /appX - Path of the route is removed before matching the path.

If a client side URL is to be generated, the required /appX/ - Path is prepended to the generated URL.

So it's now possible to put multiple apps on the same domain with the same code and just a different ROOT_URL!

It also works for server side routes as far as I see, I think it's because the HTTP Handler is respecting (and cropping out the Subdirectory according to ROOT_URL) by default.

OK, THERE'S ONE ISSUE THOUGH: *Routes will break* where routes have been hardcoded like

'mySubdir/route1'
'mySubdir/route2'

while having the ROOT_URL set to something like "http://mydomain/mySubdir".

If it'd be better to make this optional in some way or check and warn in case of routes like this I could try to add that as well if you'd like.

Best wishes

Daniel