4

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();
P3anuts
  • 461
  • 1
  • 9
  • 24

2 Answers2

2

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 "..".)

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63
0

You could also use ClassPathResourceManager.

ResourceManager rm = new ClassPathResourceManager(getClass().getClassLoader(), "dist");
ResourceHandler handler = new ResourceHandler(rm);
nashter
  • 1,181
  • 1
  • 15
  • 33