【问题标题】:fastify serve angular6 applicationfastify 服务 angular6 应用
【发布时间】:2018-11-30 09:22:17
【问题描述】:

我有一个问题。 我有一个 angular6 应用程序和一个带有 fastify 的后端。 Fastify 服务应用程序:

fastify.use(['/'], serveStatic(path.join(__dirname + '/../dist/')));

在 dist 文件夹中有 angular build。

使用 node index.js 命令启动我的应用程序

在 localhost:3000/fastify 上为应用程序提供服务,但是当我尝试刷新 localhost:3000/user fastify 时响应 404 Not Found!因为他在他的 API 中搜索路径 /user 但 /user 是一个角度路线。

我该如何解决这个故障?

【问题讨论】:

    标签: node.js angular fastify


    【解决方案1】:

    您应该使用一些前缀分隔所有 api 路由,例如 /api。然后,您可以将所有 URL 不以 /api 开头的请求重定向到 Angular 索引文件 - 因为那是前端路由。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2022-01-25
      • 2019-02-06
      • 2019-02-16
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多