-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Default reactive route returns 404 #38840
Comments
I am not sure what you mean by this. Can you clarify please? Thanks |
I was in a hurry yesterday, sorry! In order to have a small and leightweight service, I deliver the frontend using Quarkus. This is how i make sure the single page app is loaded correctly in classic mode: void init(@Observes Router router) {
router.getWithRegex("/.*").last().handler(rc -> {
if (rc.normalizedPath().equals("index.hmtl"))
rc.fail(404);
else
rc.reroute("index.hmtl");
});
} But in reactive mode, this route never matches! |
Thanks for the update, it's very helpful, but I still don't fully understand what |
It is the same code, but some route/handler which is executed before calls the 404 instead of rc.next(), so the list of routes is not processed to the end. void init(@Observes io.vertx.mutiny.ext.web.Router router) {
router.getWithRegex("^(?!/assets\|/api\|/index\\.html).*").handler(rc -> {
rc.reroute(reroutePath);
});
} |
See here: https://stackoverflow.com/questions/66965460/quarkus-how-to-implement-routing-for-single-page-apps |
Gotcha, thanks! I'll leave it to @cescoffier. Also @ia3andy might have some ideas. |
@gmuellerinform, @geromueller have you tried https://github.com/quarkiverse/quarkus-quinoa/? It features SPA routing: https://docs.quarkiverse.io/quarkus-quinoa/dev/advanced-guides.html#spa-routing |
@ia3andy I had a look at it, but is solved things I do not need (building frontend, proxies etc) |
I just found this while looking at quinoa: https://github.com/quarkusio/quarkus/blob/main/extensions/resteasy-reactive/quarkus-resteasy-reactive/spi-deployment/src/main/java/io/quarkus/resteasy/reactive/server/spi/ResumeOn404BuildItem.java This seems like a very complicated way to do something very common.. |
That is RESTEasy Reactive specific, it has no effect when using routes directly |
@geoand Are you sure? It actually says it does change routing behavior... |
I am |
But why does quinoa have to use it then to allow SPA routing? |
The reason it says that is because RESTEasy Reactive itself executes (from a Vertx perspective at least) as one big complicated route. The build item you see allows the next route in the chain to continue the processing when RESTEasy Reactive has not matched the URL |
I mean, yes it is RESTEasy Reactive specific, but then this needs to be changed ;-) |
I think there is an issue to make this easier, let me find it.. |
Could you add an build time option for this, instead if having to create an extension? |
@phillip-kruger didn't we talk about changing the 404 handling in dev mode to use the dev-ui instead or something? I can't find any issue about it? |
Yea we did, but nothing has been done yet. I have a branch with the index.html page now using Dev UI, I think that is a start. |
AFAIK the problem is that the 404 handling is done by RR (and RC) with the same routing priority as any other RR resources which is not allowing any other service/extension to provide their own routes with a lower priority than RR. The 404 handling should be dealt with at a lower priority to allow anyone to hook in. Still if it's not the case yet, I am pretty sure their are reasons for it (probably the side effects and complexity it could involve). |
@gmuellerinform if you can, my recommendation would be to put your REST api on a specific sub-path (i.e /api), this way you can use the workaround suggested in the Quinoa doc: |
Sure, we can do that |
This is a useful (albeit advanced) option for users that want to use custom routes to handle cases where RESTEasy Reactive does not match the URL path. Closes: quarkusio#38840
Here you go :) |
perfect, thanks a alot!! |
🙏 |
Add configuration option for resuming on 404
Describe the bug
For single page apps unknown routes should return index.html. In classic mode it is possible to add a "last" route which redirects to index.html. In reactive mode the default route returns 404, which breaks the router chain.
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
No response
Quarkus version or git rev
No response
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: