Node.js更改静态文件的路径

时间:2017-11-02 11:51:41

标签: javascript node.js express

当我在其他路线时,一切都很好,但是当动态创建子页面时,我得到一个错误500,我没有favicon或我的js文件。为什么会这样?

- 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"));

2 个答案:

答案 0 :(得分:1)

缺少括号可能是问题。

res.render("vehicle", { name: req.user }); // you missed the closing ')' here

答案 1 :(得分:1)

试试这段代码

app.use(express.static(path.join(__dirname, "public")));