How to serve static files from file system with Quarkus

Viewed 497

I am running a Quarkus application server (Serving REST via HTTP) behind an ngnix web server. Now I want to serve static content (Flutter web-app) from file system from with the same base url. Letting ngnix serve it would do it but I would like to use the access control configured in Quarkus application.properties for web app part, too.

Shouldn't it be possible to let my Quarkus server also serve the static stuff?

As server and app are in separate repos and maintained separately, both parts should be deployable independently.

I would expect this to be a common issue but can't find a simple solution.

Any hint?

2 Answers

You can leverage Quarkus Reactive Routes with something like:

@ApplicationScoped
public class StaticAuthenticatedDeclarativeRoute {

    @Route(path = "/auth-static/*", methods = Route.HttpMethod.GET)
    @Authenticated
    void secureStatic(RoutingContext rc) {
        StaticHandler.create(FileSystemAccess.RELATIVE, "content/").handle(rc);
    }

}

and consider the path can also be absolute using FileSystemAccess.ROOT.

I have the same problem (but not the requirement to serve from filesystem).

What you can do according to the Quarkus documentation - HTTP Reference:

Put your static web content into META-INF/resources directory of your application.

Then build your quarkus application and deploy it.

Related