【问题标题】:Use Undertow to serve AngularJS使用 Undertow 服务 AngularJS
【发布时间】:2014-09-04 04:44:25
【问题描述】:

我想使用 Undertow 作为一个简单的 Web 服务器来为 AngularJS 应用程序提供服务。 AngularJS 应用程序所需的其余服务由 Apache Camel 提供,因此我只需要使用 Undertow 为 Angular 应用程序提供服务。

我已阅读文档但无法使其正常工作,对我做错了什么有任何想法吗?

这是我现在用于启动 Underow 服务器的代码

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

【问题讨论】:

  • 您也应该禁用目录列表。

标签: java angularjs undertow


【解决方案1】:

您也可以使用 ClassPathResourceManager。

ResourceManager rm = new ClassPathResourceManager(getClass().getClassLoader(), "dist");
ResourceHandler handler = new ResourceHandler(rm);

【讨论】:

    【解决方案2】:

    File("../dist") 是问题所在。使用绝对路径或至少一个不带“..”的路径,那么它应该可以工作。

    (Undertow 包含一个健全性检查,将资源的计算文件路径与其规范路径进行比较,该路径在“.”和“..”处中断。)

    【讨论】:

      猜你喜欢
      • 2016-06-18
      • 2015-03-19
      • 2015-04-02
      • 1970-01-01
      • 2015-03-08
      • 2014-11-15
      • 2017-09-13
      • 1970-01-01
      相关资源
      最近更新 更多