【发布时间】:2018-06-11 20:50:02
【问题描述】:
当我从 node express 提供我的 angular 5 应用程序时,我在访问 domain.com 时遇到了这个问题,因为 express static 服务 index.html 但是当我访问 domain.com/something 它正常工作可以帮助我如何解决这个问题
app.use(express.static(path.join(__dirname, 'dist'))); //This line serves index.html how to deny it
app.use("/api", routes);
app.get('*', function(req, res) { //The reason it needs to be * so that it works with angular routes or it wont work
//This is never called when i visit domain.com. but it does when i visit domain.com/somthing
console.log("i was serverd");
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
提前致谢:)
【问题讨论】:
-
你想在你的路由中服务
dist/index.html而不是express.static吗? -
@vibhor1997a 是正确的