'How to serve static files from file system with Quarkus
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?
Solution 1:[1]
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
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mrizzi |