Use Undertow to serve AngularJS

寵の児 提交于 2019-12-05 02:05:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!