[英]fastify serve angular6 application
i have a question. 我有个问题。 I have an angular6 application and a back-end with fastify.
我有一个angular6应用程序和一个带有fastify的后端。 Fastify serve application so:
这样固定服务应用程序:
fastify.use(['/'], serveStatic(path.join(__dirname + '/../dist/')));
in the dist folder there is the angular build. 在dist文件夹中有角度构建。
start my application with node index.js command 使用node index.js命令启动我的应用程序
on localhost:3000/ fastify serve the application, but when i try to refresh localhost:3000/user fastify respond 404 Not Found! 在localhost:3000 /上的fastify服务应用程序,但是当我尝试刷新localhost:3000 / user上的fastify响应404 Not Found! Because he search path /user in his API but /user is an angular route.
因为他在自己的API中搜索路径/ user,但是/ user是一条有角度的路线。
How can I solve this malfunction? 如何解决此故障?
You should separate all your api routes with some prefix, for example /api
. 您应该使用一些前缀分隔所有api路由,例如
/api
。 Then you can redirect all requests with URL not starting with /api
to Angular index file - because that's frontend routes. 然后,您可以将所有不以
/api
开头的URL的请求重定向到Angular索引文件-因为这是前端路由。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.