'Resource handler in quarkus

I need a resource handler to serve static resources. I know that to serve static resources I should place them in META-INF/resources. I want to add resource handler with URL path patterns and configure the locations to serve static resources.



Solution 1:[1]

I would suggest looking into Quarkus' Reactive Routes. They essentially allow you to register a Vert.x Route in a more declarative way. In the implementation of your Route, you can do whatever you like. For reference, this is how Vert.x's serves static resources.

Solution 2:[2]

Based on previous answer https://stackoverflow.com/a/68347961/8284722, a solution can be:

@ApplicationScoped
public class StaticContentDeclarativeRoute {

    @Route(path = "/static/*", methods = Route.HttpMethod.GET)
    void staticContent(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 geoand
Solution 2 mrizzi