问题描述
我正在使用reactjs和nodejs技术开发一个Web应用程序,此后,我将其部署在HEROKU上,但是当我在Heroku上运行时,出现了一个错误 ENOENT:没有这样的文件或目录,状态为'/ app / client / build'“ 而且我观察到一件事 stat'/ app / client / build',我不知道为什么这条路径不会改变,因为我是reactjs和nodejs的新手。
server.js
var restify = require("restify");
var server = restify.createServer();
function respond(req,res,next) {
res.send('Hello Restify!');
}
server.get('/hello',respond);
server.get("/*",restify.plugins.serveStatic({
directory: __dirname+"/client/build",default: 'index.html',appendRequestPath: false
})
);
var port = process.env.PORT || 5000;
server.listen(port,function() {
console.log("Listening on " + port);
});
解决方法
之所以可能会出错,是因为/client/build
目录可能不存在。
- 确保在执行
git add
时要包含此文件夹(例如,您可能拥有.gitignore
文件,但该目录除外) - 一旦推送到heroku,您可以通过以下方式验证服务器上的所有文件:
heroku run bash # should take you to the current dyno's bash
ls # do you see your client directory?
cd client
ls # do you see your build directory?
随时发布您的结果,并告诉我们是否有帮助。