问题
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();
回答1:
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 "..".)
回答2:
You could also use ClassPathResourceManager.
ResourceManager rm = new ClassPathResourceManager(getClass().getClassLoader(), "dist");
ResourceHandler handler = new ResourceHandler(rm);
来源:https://stackoverflow.com/questions/24733619/use-undertow-to-serve-angularjs