使用 vert.x 加载静态 angular2 web 项目

Load static angular2 web project using vert.x

我们可以使用 vert.x 加载静态网页,方法是将 index.html 放入资产文件夹并在 Router

中给出其路径
router.route("/assets/*").handler(StaticHandler.create("assets"));

如果我将 Angular2 构建项目放入资产文件夹并尝试加载 index.html,浏览器无法理解 Angular2,因为浏览器中没有加载任何依赖项。

据我所知,我们可以使用 lite-server 或 node 来 运行 Angular2 项目。

有没有什么方法可以使用 vert.x 来加载 Angular2 项目,或者有没有其他没有网络服务器的解决方案?

Vert.x 文档所述,

Any requests to paths handled by the static handler will result in files being served from a directory on the file system or from the classpath. The default static file directory is webroot but this can be configured.

因为您已将默认 Web 根文件夹配置为 assets 对路径 [=18= 的任何请求]/assets/ 将导致在 assets/assets/ 下提交的文件将按规定送达也通过官方文档:

For example, if there was a request with path /static/css/mystyles.css the static serve will look for a file in the directory webroot/static/css/mystyle.css.

例如带有路径 /assets/js/angular2.js 的请求将指示服务器在 assets/assets/js/angular2.js 下查找文件 因此你应该:

  • 将您的静态资产移动到 assets/assets/ 文件夹下。
  • 或者保留默认根文件夹并将静态文件放在 webroot/assets.

附加组件:对于任何遇到此问题的人 post。 下面的代码段用于处理浏览器上的刷新。

堆栈 - Vertx 服务 angular 2 个文件。

   // Create a router endpoint for the static content.

   basically route any files - js, css, jpg etc
   router.route("/*")
   .handler(StaticHandler.create("webroot").setCachingEnabled(false));

   // so anything else re route to home page
   router.route("/*").handler(rc -> {
        logger.info("For refresh handling");

        rc.response().sendFile("webroot/index.html");

   });