Comments (26)
Sure, we can do that
from quarkus.
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
I am not sure what you mean by this.
Can you clarify please?
Thanks
from quarkus.
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!
from quarkus.
Thanks for the update, it's very helpful, but I still don't fully understand what But in reactive mode, this route never matches
means.
Mind providing an example for this as well?
from quarkus.
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.
But, when I move my route up in the order, just before the build in routes (order=10000), I have to guess if it is an SPA route or some actual resource / static file. My workaround curently looks like this:
void init(@Observes io.vertx.mutiny.ext.web.Router router) {
router.getWithRegex("^(?!/assets\|/api\|/index\\.html).*").handler(rc -> {
rc.reroute(reroutePath);
});
}
from quarkus.
See here: https://stackoverflow.com/questions/66965460/quarkus-how-to-implement-routing-for-single-page-apps
I was actually surprised that quarkus does not support this out of the box...
from quarkus.
Gotcha, thanks!
I'll leave it to @cescoffier. Also @ia3andy might have some ideas.
from quarkus.
@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
from quarkus.
@ia3andy I had a look at it, but is solved things I do not need (building frontend, proxies etc)
from quarkus.
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..
from quarkus.
That is RESTEasy Reactive specific, it has no effect when using routes directly
from quarkus.
@geoand Are you sure? It actually says it does change routing behavior...
from quarkus.
I am
from quarkus.
But why does quinoa have to use it then to allow SPA routing?
from quarkus.
The reason it says that is because RESTEasy Reactive itself executes (from a Vertx perspective at least) as one big complicated route.
Normally when RESTEasy Reactive can't match a URL it ends the request with 404.
The build item you see allows the next route in the chain to continue the processing when RESTEasy Reactive has not matched the URL
from quarkus.
I mean, yes it is RESTEasy Reactive specific, but then this needs to be changed ;-)
from quarkus.
I think there is an issue to make this easier, let me find it..
from quarkus.
Could you add an build time option for this, instead if having to create an extension?
from quarkus.
@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?
from quarkus.
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.
from quarkus.
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).
from quarkus.
@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:
https://docs.quarkiverse.io/quarkus-quinoa/dev/advanced-guides.html#spa-routing
from quarkus.
@ia3andy Thanks! This is what I am doing atm. But it is ughly... And I think a simple build time config could help us all:
from quarkus.
Here you go :)
from quarkus.
perfect, thanks a alot!!
from quarkus.
🙏
from quarkus.
Related Issues (20)
- PostgresQL IT tests failing with Mandrel 24.2 (for JDK 24) HOT 2
- Single quotes in variables break string HOT 4
- Can't update Quarkus with quarkus cli or mvn HOT 2
- Pushing config doc to Dev UI is very costly HOT 4
- REST endpoints not found if no entity is present in module HOT 1
- OIDC: List of JWKS is not checked without specified kid HOT 2
- access to default named beans in qute typesafe templates HOT 2
- Auto configure prometheus scraping for lgtm dev service HOT 4
- [Hibernate Reactive Panache] Concurrent request - HR000069: Detected use of the reactive Session from a different Thread HOT 10
- implements ReaderInterceptor, WriterInterceptor could not get response headers~ HOT 1
- gRPC client deadline config semantics HOT 5
- To be able to schedule clusterized tasks and non-clusterized (in memory) timers HOT 3
- Panache deleteAll doesn't recognize the entity HOT 3
- `quarkus image build` overrides `container-image.group` with the docker username HOT 1
- Response when invalid endpoint is called be agent responsive HOT 9
- Quarkus Diameter Stack
- Support connection reset on cancellation for generated REST clients HOT 13
- Build fails if a dependency contains dependency to old smallrye-config HOT 2
- REST Client: support download multiple files multipart/form-data HOT 2
- Support Spring Data `JpaRepository#getReferenceById(ID)` (replacement for deprecated `getOne(ID)`) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quarkus.