'What is the best practice for serve HTML files in Quarkus

I don't want the extension of my HTML files to show up in the address bar like index.html, login.html. Instead, I want these files to be accessed with patterns like /HOMEPAGE /LOGIN

I don't hold these files under the resources/META-INF/resources directory because I also don't want these files to be accessed directly from the address bar by typing the file name.

I could not find a built-in solution in Quarkus to meet these needs. So I followed my own solution.

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/LOGIN")
public String loginPage() throws IOException {
    String fullPath = PATH + "login.html";
    return Files.readString(Paths.get( fullPath ));
}

But I'm not sure if this is the right solution. Are there any best practices on Quarkus for the kind of needs I mentioned?



Solution 1:[1]

Using Quarkus Reactive Routes, you can create a route like:

@ApplicationScoped
public class StaticContentDeclarativeRoute {

    @Route(path = "/homepage", methods = Route.HttpMethod.GET)
    void indexContent(RoutingContext rc) {
        StaticHandler.create(FileSystemAccess.RELATIVE, "content/index.html").handle(rc);
    }

}

so that in this way at the URL /homepage you'll have the index.html page served.
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