[英]Heroku: Failed to load resource: the server responded with a status of 404 (Not Found)
I have angular 6 app in my local machine , everything works perfectly as I want, after finishing the project I deployed it to heroku, when I run my app here is the link to the app in heroku : Testing App 我的本地计算机上有angular 6应用,完成项目后,将其部署到heroku,一切正常运行,当我运行我的应用时,这是heroku中该应用的链接: 测试应用
as you can see I get the following error in console browser 如您所见,我在控制台浏览器中收到以下错误
Failed to load resource: the server responded with a status of 404 (Not Found)
加载资源失败:服务器响应状态为404(未找到)
App repo in github github中的应用回购
for quick reference , Here is server.js 为了快速参考,这是server.js
const express = require('express'); const bodyParser = require('body-parser'); const cors = require('cors'); const path = require('path'); const app = express(); const port = process.env.PORT || 3000 app.use(express.static(path.join(__dirname, '/majeni/dist/majeni/'))); app.use(bodyParser.json()); app.use(cors()); const forceSSL = function () { return function (req, res, next) { if (req.headers['x-forwarded-proto'] !== 'https') { return res.redirect( ['https://', req.get('Host'), req.url].join('') ); } next(); }}app.use(forceSSL()); app.get('/*', function (req, res) { res.sendFile(path.join(__dirname + '/majeni/dist/majeni/index.html')); }); app.listen(port, () => { console.log('Server started on port '+port); });
Here is heroku logs. 这是heroku日志。
2018-08-16T17:46:38.891333+00:00 app[web.1]: Error: ENOENT: no such file or directory, stat '/app/majeni/dist/majeni/index.html'
2018-08-16T17:46:38.891333 + 00:00 app [web.1]:错误:ENOENT:没有这样的文件或目录,stat'/app/majeni/dist/majeni/index.html'
What is wrong with my code? 我的代码有什么问题?
Heroku is failing to find the dist
directory, because it is not part of your committed repository. Heroku无法找到
dist
目录,因为它不属于已提交的存储库。 The dist
directory has been added to the .gitignore
file. dist
目录已添加到.gitignore
文件中。
It's generally a bad idea to commit the dist
directory, so we should generate it on Heroku. 提交
dist
目录通常是个坏主意,因此我们应该在Heroku上生成它。
You can do this by adding a postinstall script in package.json
您可以通过在
package.json
添加安装后脚本来完成此操作
"scripts": {
"postinstall": "ng build"
}
More info can be found in the Heroku docs 更多信息可以在Heroku文档中找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.