Coder Social home page Coder Social logo

Comments (26)

geoand avatar geoand commented on July 19, 2024 1

Sure, we can do that

from quarkus.

geoand avatar geoand commented on July 19, 2024

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.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

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.

geoand avatar geoand commented on July 19, 2024

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.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

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.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

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.

geoand avatar geoand commented on July 19, 2024

Gotcha, thanks!

I'll leave it to @cescoffier. Also @ia3andy might have some ideas.

from quarkus.

ia3andy avatar ia3andy commented on July 19, 2024

@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.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

@ia3andy I had a look at it, but is solved things I do not need (building frontend, proxies etc)

from quarkus.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

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.

geoand avatar geoand commented on July 19, 2024

That is RESTEasy Reactive specific, it has no effect when using routes directly

from quarkus.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

@geoand Are you sure? It actually says it does change routing behavior...

from quarkus.

geoand avatar geoand commented on July 19, 2024

I am

from quarkus.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

But why does quinoa have to use it then to allow SPA routing?

from quarkus.

geoand avatar geoand commented on July 19, 2024

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.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

I mean, yes it is RESTEasy Reactive specific, but then this needs to be changed ;-)

from quarkus.

ia3andy avatar ia3andy commented on July 19, 2024

I think there is an issue to make this easier, let me find it..

from quarkus.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

Could you add an build time option for this, instead if having to create an extension?

from quarkus.

ia3andy avatar ia3andy commented on July 19, 2024

@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.

phillip-kruger avatar phillip-kruger commented on July 19, 2024

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.

ia3andy avatar ia3andy commented on July 19, 2024

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.

ia3andy avatar ia3andy commented on July 19, 2024

@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.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

@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:

initClassFactory, launchModeBuildItem.getLaunchMode(), servletPresent || !resumeOn404Items.isEmpty());

from quarkus.

geoand avatar geoand commented on July 19, 2024

Here you go :)

from quarkus.

gmuellerinform avatar gmuellerinform commented on July 19, 2024

perfect, thanks a alot!!

from quarkus.

geoand avatar geoand commented on July 19, 2024

🙏

from quarkus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.