我有一个问题。 我有一个 angular6 应用程序和一个带有 fastify 的后端。 Fastify 服务应用程序如下:
fastify.use(['/'], serveStatic(path.join(__dirname + '/../dist/')));
在 dist 文件夹中有 Angular 构建。
使用 node index.js 命令启动我的应用程序
在 localhost:3000/fastify 上为应用程序提供服务,但是当我尝试刷新 localhost:3000/user fastify 时响应 404 Not Found!因为他在他的 API 中搜索路径/user 但/user 是一个 Angular 路线。
如何解决此故障?
最佳答案
您应该使用一些前缀分隔所有 api 路由,例如 /api
。然后,您可以将 URL 不以 /api
开头的所有请求重定向到 Angular 索引文件 - 因为那是前端路由。
关于node.js - Fastify 服务 Angular6 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53554584/