node.js - 加载资源失败:服务器响应状态为 404(未找到) ENOENT:没有这样的文件或目录,stat '/client/build/index.html'
问题描述
https://github.com/sw9142/thankshare
在过去的几天里,我一直在努力解决这个错误,但我不能..
检查heroku日志,它说找不到'/client/build/index.html'。
2021-07-02T04:46:14.791646+00:00 app[web.1]: Error: ENOENT: no such file or directory, stat '/client/build/index.html'
这是开发工具中出现的错误和另一个错误(这是导致404错误的原因吗??)
Refused to load the font '<URL>' because it violates the following Content Security Policy directive: "font-src 'self' data:".
Failed to load resource: the server responded with a status of 404 (Not Found)createError.js:16
Uncaught (in promise) Error: Request failed with status code 404
at e.exports (createError.js:16)
at e.exports (settle.js:17)
at XMLHttpRequest.p.onreadystatechange (xhr.js:62)
所以这就是我一直在尝试解决这个问题的方法,将以下内容添加到 server.js
if (process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, "/client/build")));
app.get('*', function (req, res) {
const fullPath = path.join(__dirname, '../client',
'build', 'index.html')
res.sendFile(fullPath)
})
}
谁知道我做错了什么,请告诉我!!!
解决方案
推荐阅读
- python - 对收益和回报感到困惑
- c# - Xamarin Forms CarouselPage ActivityIndicator in every ContentPages not working
- floating-point - How to round micros?
- linux - Ubuntu 18.04 内核转储文件生成 (KDUMP)
- pentaho - 在 Pentaho 上创建与数据库的连接时如何修复空指针异常?
- android - 活动不应在 mHomeReady 之前启动 - Android Studio
- html - HTML 代码产生语法错误但仍然有效;“正确”的代码不
- javascript - ngOnInit() 被调用两次
- javascript - 即使是javascript调用,音频标签也无法在移动设备中播放
- angular - Angular 4 - 带有 FormGroup 控件的 ngIf