Search code examples
javaangularjsundertow

Use Undertow to serve AngularJS


I would like to use Undertow as a simple web server for serving an AngularJS application. The rest services needed by the AngularJS application is served by Apache Camel so I would only need to serve the Angular App using Undertow.

I have read the documentation but cannot get it working, any ideas on what I am doing wrong?

Here is the code that I have now for starting Underow server

Undertow server = Undertow.builder()
            .addHttpListener(8080, "localhost")
            .setHandler(resource(new FileResourceManager(new File("../dist"),10))
                    .addWelcomeFiles("../dist/index.html")
                    .setDirectoryListingEnabled(true))
            .build();
    server.start();

Solution

  • File("../dist") is the problem. Use an absolute path or at least one without "..", then it should work.

    (Undertow contains a sanity check comparing the computed file path for a resource with its canonical path, which breaks on "." and "..".)