【发布时间】:2019-08-22 10:10:49
【问题描述】:
我在ts中有这个快递服务器,这是转换后的js,代码:
class App {
constructor() {
this.app = express();
...
this.config();
...
}
config() {
if (process.env.NODE_ENV === 'production') {
// Serve any static files
this.app.use(express.static(path.join(__dirname, '../../frontend/build')));
// Handle React routing, return all requests to React app
this.app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../../frontend/build', 'index.html'));
});
}
}
}
exports.default = new App().app;
但我在 heroku 上收到此错误:
错误:ENOENT:没有这样的文件或目录,stat '/app/frontend/build/index.html'
我检查了 heroku bash 上的目录并在那里构建,这不是我第一次部署应用程序,但这次是打字稿,我习惯了 javascript,我想这可能是不同的?我 100% 确定该文件夹正确地定位在 config() 上。帮忙?
【问题讨论】:
-
path.join(__dirname, '../../frontend/build') ... 你确定要像这样加入 dirrname 吗?因为你已经在 dirname 中了。为什么要回去?也许 path.join(__dirname, '/frontend/build'
标签: reactjs typescript express