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
Mount two applications in the same path #796
Comments
Doesn't really make sense to me. Why would you want to do that? |
why wouldn't work? highest priority routes would take precedence. that's the rack's point: stackable apps, if a route doesn't match try the next app, no? it seems to work if I do "use AnotherApp" in my main app so maybe I just need to do that |
Yes, thats racks point: stackable apps. How should the router middleware decide which app to use without peeking upwards? Using Sinatra as a middleware does that implicitly: The The Padrino::Router does something different: it decides which path to between 2 different (and possibly large) middleware stacks. Allowing it to retry on a second app would be harmful, actually - we cannot guarantee that all middlewares should be allowed to run twice during a request and both branches could include such a middleware. Also, chances are that calling all stacks in worst case would be a very slow thing. Padrino is Rack galore in that respect: you have multiple middleware stacks that can be switched between with all advantages and problems. |
thanks for your replies Etienne, Florian. really appreciated them if I use the sinatra's approach( |
It shouldn't be a problem. If it is, file a bug. Performance-wise, its the better approach, as Sinatra makes sure that it behaves well as a middleware. You shouldn't add things like exception handling, session handling etc. to the Performance-wise, its the better approach. Think about ordering a bit, but otherwise, its fine. |
ok thanks man, I am closing this issue |
I ran in to this issue today on a project I'm planning out:
This use case doesn't seem exceptionally contrived or rare to me. A lot of people build APIs with Padrino, and many APIs are RESTfully structured along the same URLs as their web interface, differing by extension. It's a common alternative to nesting everything under '/api'. Also, Grape is an excellent and widely used Rack API gem. It's easy and efficient to develop your Grape APIs in a single file as a padrino app and it sucks not being able to mount it on top of your existing url structure for your web interface. Particular to my scenario, all of my views get their data by consuming the API, so it really doesn't feel natural throwing the root views in with the api, which i what I plan on doing. |
It didn't occur to me that
Normally I'd override api_status to always be 301, but I'm integrating with a company API not served from '/api', so I want to keep the status codes consistent. |
@christhekeele you could use |
I'll reopen this. As we're talking about a router rework anyways and most routers now support Cascade-Like functionality, we should allow this. It still has interesting performance-implications though, so be warned. |
If one app is mounted to '/foo' and the second to '/foo/bar' and we Our tests depend on the second behavior https://github.com/padrino/padrino-framework/blob/master/padrino-core/test/test_router.rb#L47 |
Arguably, it should favor the order they're defined/mounted, since using route specificity to determine priority sounds highly arbitrary, hard to code, and hard to reason about. |
Okay, then I have a branch ready to break that one test: https://github.com/padrino/padrino-framework/commits/cascade-apps It respects the mounting order and passes to the next app on 404. Commit: 57d2999 |
Closing in favor of #1471 |
for example I want to mount to apps in '/' but it doesn't work. I think this should be doable.
The text was updated successfully, but these errors were encountered: