[英]Node.js changing path to static files
When I am other route everything is Ok, but when a subpage is being created dynamically I get an error 500 and I do not have favicon or my js file. 当我使用其他路由时,一切正常,但是当动态创建子页面时,出现错误500,并且没有favicon或我的js文件。 Why is this happening?
为什么会这样呢?
- My route
app.get("/:id/vehicle", isLoggedIn, (req, res) => {
res.render("vehicle", { name: req.user }); <- edited, thanks
});
- Error message, code 500
GET http://localhost:3000/xxx/common/js/main.js net::ERR_ABORTED
- Path to public directory
app.use(express.static(path.join(__dirname, "/public")));
app.use(favicon(__dirname + "/public/favicon.ico"));
缺少括号可能是问题所在。
res.render("vehicle", { name: req.user }); // you missed the closing ')' here
试试这个代码
app.use(express.static(path.join(__dirname, "public")));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.