Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support routing to start below a subdirectory on the server #800

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

DanielDornhardt
Copy link

Hello,

i created this patch to be able to run apps in a subdirectories of a domain.

Eg. if I want to have an app on

mydomain.com/beta ,

it's possible to tell meteor that via a the ROOT_URL environment variable like this:

ROOT_URL="http://mydomain.com/beta" mrt ,

but IronRouter didn't take that into account until now, meaning the URL mydomain.com/beta/hello would match the route "/beta/hello", instead of just "hello".

This means that one would have to either manually prepend the /subdirectory/on/the/server to each route, or invent some other scheme to dynamically create routes when the same app should be available ob different subdirectories on different servers for example.

Meteor provides a runtime variable, meteor_runtime_config.ROOT_URL_PATH_PREFIX , which contains the /subdirectory/on/the/server in which the app is running, both on the client and the server.

We therefore can use this variable to prepend it to created URLs in the router and remove it from the URLs when trying to match routes.

This then allows for multiple apps on different subdirectories.

Server side routes seem to work as well with this patch as Meteor takes into account the ROOT_URL_PATH_PREFIX when creating HTTP endpoints.

THE ONLY THING NOT SO NICE about this patch is that it will break existing routes containing the subdirectories in the routes.

So maybe this should be made configurable, or check against manually set ROOT_URL_PATH_PREFIXes manually set by logging a warning to the console? And maybe disable this functionality for these routes?

Please have a look at the patch, see if it makes sense, if I forgot anything obvious and if there's anything I could do to make it more palatable.

Thanks for the great work everybody and best wishes!

PS: I've submitted a pull request to CollectionFS too, if anyone needs to use that as well as IronRouter, check it out here: https://github.com/CollectionFS/Meteor-cfs-access-point/pull/8 or here: https://github.com/DanielDornhardt/Meteor-cfs-access-point/tree/supportSubdirectoriesOnDomain (at least until it's merged.)

@hellogerard
Copy link

@DanielDornhardt,

This is a great feature and would come in handy when packages create its own IR routes.

If I understand your PR correctly, there's some references to a mount option in the next branch of IR. See here and here, for example. Looks similar to this feature. I'm not sure how complete it is. You could try out that branch and see if it does what you need.

@cmather
Copy link
Contributor

cmather commented Oct 4, 2014

Yeah, can we try to use the mount feature?

@DanielDornhardt
Copy link
Author

Hi, I'd love to try it, but how exactly is it supposed to work? I didn't see any reference in the "old" docs nor in the guide?

And it would also be nice to know how mounts are supposed to work, are they meant to

a) plug together applications from multiple routes for one bigger application, or
b) allow for an application to support being put into a subdirectory, as in "i want to run five...x instances of the same app in different URLs on the same domain" as was the point of this ticket, eg. supporting the path which might be included in the ROOT_URL environment variable?

c) both?

@cmather
Copy link
Contributor

cmather commented Oct 27, 2014

@DanielDornhardt, will come back to this on next release. Definitely a use case that should be supported. Just need to get this release ready for v1 and then get to the next batch of features. I'd like to spend more time looking at your implementation.

For your question above:

It's meant to say, this handler or function will get called for any url after a certain point. So if you mount a handler at /some/mount/point then it will handle /some/mount/point/a and /some/mount/point/a/b. Might not completely address this use case. I also removed the Router.use function for now until we hammer it out a little more.

@DanielDornhardt
Copy link
Author

Hi, thanks for the feedback.

My "implementation" was a simple fix for the old, pre-refactoring branch... So I am not sure if it still applies to the new Iron-Router. But yes, I think this should be supported.

I am going to watch the eventedmind - IronRouter - tutorial one of these days, and maybe after that I'll be able to contribute a bit more.

I also think that there might be another valuable aspect to this:

The problem of "composability" of different packages... eg. Things like forums, admin or blog packages... right now it seems to me that the only simple option for adding packages with "pages" to an app is to use hard-coded routes, eg. the blog package, which uses /blog/ by default.

In other systems (actually I am only familiar with this feature from Django, but it feels so intuitive and logical), it's possible to add a set of Routes / a routing configuration below another route.

So the user could be allowed to mount the /blog/ package wherever he wanted. Below root, if he would like to, or maybe at /personal/blog .

I am not sure how and where this could be added with the router package, as it would probably imply having multiple Router - objects, with one being attached to a route of the other... and the Router seems to have a kind of Singleton-ish / static role at the moment. But I still thing that'd be a great feature to provide to allow users to allow more turnkey app packages.

https://docs.djangoproject.com/en/1.7/topics/http/urls/#including-other-urlconfs

@cmather
Copy link
Contributor

cmather commented Oct 27, 2014

Hey @DanielDornhardt, Thanks for the link. That's helpful. Being able to mount routes or even a completely new router should be supported.

@DanielDornhardt
Copy link
Author

Hello, I finally got around to update the project I needed this for to IronRouter 1.0+ ... unfortunately the patches I did for the old branch didn't work anymore, so I re-did the "incorporation of the ROOT_URL subdirectory" - fix.

I created this pull request for Iron.Url: iron-meteor/iron-url#13 - and for IronRouter, basically only the Iron.Url - dependency would need to reference the newer Iron.Url - version: https://github.com/DanielDornhardt/iron-router-2/compare/incorporateMeteorROOT_URLSetting?expand=1

I hope this makes it into Iron-Router, thanks and best wishes!

PS: It'd be great to have a more clear overview over the IronRouter - Stack / Middleware / Layer - stack, but I didn't really have the time to get into it, are there some specs / is there some introduction to it?

@DanielDornhardt
Copy link
Author

I reopen this here again, sorry, because I felt like Iron-Url - Pull - Requests might not get noticed as quickly. I can't create a proper pull request for Iron-Router at the moment unfortunately, see the Iron.Url Pull request above for an explanation. The Iron-Router - updates probably would need to be done manually. Thanks and best wishes! And have a great weekend everybody too. :)

@DanielDornhardt
Copy link
Author

Alright, please put this on hold for another day or two, I'm still ironing out some issues

@DanielDornhardt
Copy link
Author

Ok, this is as good as it gets for now from my side: iron-meteor/iron-url#13

Sorry, this got a bit convoluted, I hope it's manageable.

Best wishes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants