【发布时间】:2020-05-09 23:46:07
【问题描述】:
这是我的应用程序的简要结构
├── client
│ └─ build
│ └─ index.html
│
│
├── server
│ └─ index.js
Heroku 上的生产代码如下:
// index.js
if (process.env.NODE_ENV === "production") {
// app.use(express.static(path.join(__dirname, "..", "client/build"))); // not working
app.use(express.static(path.join(__dirname, "/../client/build"))); // not working
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "/../client/build", "index.html")); // not working
});
}
下面 Heroku 的错误:
正如错误日志所说,不知何故 path.join(__dirname, "/../client/build") 没有指向服务器目录(根)之外的客户端目录,而是只需找到相同的 server 目录,例如 /server/client 这是错误的路径,甚至不存在,如上面的错误所示。
如何定位“clinet/build/”?
【问题讨论】: