at=错误代码=H10 desc="应用程序崩溃"方法=获取路径="/"
Posted
技术标签:
【中文标题】at=错误代码=H10 desc="应用程序崩溃"方法=获取路径="/"【英文标题】:at=error code=H10 desc="App crashed" method=GET path="/" 【发布时间】:2021-02-20 11:31:10 【问题描述】:我一直在尝试使用 Heroku 进行 MEAN 应用程序,但我遇到了这个错误。我不知道有什么问题...我需要一些帮助。我寻找了很多解决方案。但我有同样的错误。 我还附上了我的 git。 https://github.com/handsomehyunsu/resume/tree/heroku 谢谢。
2020-11-08T08:59:22.685557+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hyunsukimresume.herokuapp.com request_id=51fc6ab7-2c9d-431c-b8a2-2a7a82ce79c3 fwd="14.50.155.250" dyno= connect= service= status=503 bytes= protocol=https
2020-11-08T08:59:23.143224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hyunsukimresume.herokuapp.com request_id=b9cb9676-fd30-4987-9a48-3bf71fa095a3 fwd="14.50.155.250" dyno= connect= service= status=503 bytes= protocol=https
过程文件
web: node server.js
package.json
"name": "my-resume",
"version": "0.0.0",
"scripts":
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"dev": "nodemon server.js",
"postinstall": "ng build --output-path dist"
,
"private": true,
"dependencies":
"@angular/animations": "^10.1.6",
"@angular/cdk": "^10.2.7",
"@angular/common": "~10.1.5",
"@angular/compiler": "~10.1.5",
"@angular/core": "~10.1.5",
"@angular/forms": "~10.1.5",
"@angular/material": "^10.2.7",
"@angular/platform-browser": "~10.1.5",
"@angular/platform-browser-dynamic": "~10.1.5",
"@angular/router": "~10.1.5",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"bootstrap": "^4.5.3",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.10.11",
"mongoose-unique-validator": "^2.0.3",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
,
"devDependencies":
"@angular-devkit/build-angular": "~0.1001.6",
"@angular/cli": "~10.1.6",
"@angular/compiler-cli": "~10.1.5",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"nodemon": "^2.0.6",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
,
"engines":
"node": "~10.16.3",
"npm": "~6.14.8"
server.js
const debug = require('console');
const http = require('http');
const app = require('./backend/app');
const normalizePort = val =>
var port = parseInt(val, 10);
if(isNaN(port))
//named pipe
return val;
if(port >= 0)
//port number
return port;
return false;
;
const onError = error =>
if(error.svscall !== "listen")
throw error;
const bind = typeof addr === "string" ? "pipe " + addr : "port " + port;
switch(error.code)
case "EACCES":
console.log(bind + " requires elevated privileges");
process.exit(1);
break;
case "EADDRINUSE":
console.log(bind + " is already in use");
process.exit(1);
break;
default:
throw error;
;
const onListening = () =>
const addr = server.address();
const bind = typeof addr === "string" ? "pipe " + addr : "port " + port;
debug("Listening on " + bind);
;
const port = normalizePort(process.env.PORT || "3000");
app.set("port", port);
const server = http.createServer(app);
server.on("error", onError);
server.on("listening", onListening);
server.listen(port);
后端/app.js
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require("mongoose");
const postsRoutes = require('./routes/posts');
const userRoutes = require('./routes/user');
const app = express();
//mongodb connect
mongoose.connect("mongodb+srv://test_username:" + process.env.MONGO_ATLAS_PW + "@cluster0.utmlm.mongodb.net/myResume?retryWrites=true&w=majority")
.then(() =>
console.log('connected to database!!');
)
.catch(() =>
console.log('connection failed');
)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded( extended: false ));
//CORS
app.use((req, res, next) =>
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.setHeader(
"Access-Control-Allow-Methods",
"GET, POST, PATCH, PUT, DELETE, OPTIONS"
);
next();
);
app.use("/posts", postsRoutes);
app.use("/user", userRoutes);
module.exports = app;
【问题讨论】:
【参考方案1】:Heroku H10-App 崩溃可能是因为很多原因,所以我会尽力列出它们,您可以尝试检查它们。
如果您的服务器在 server.js 中并且您的 Procfile 指向 app.js,这肯定会使您的应用崩溃
将 PORT 设置为 Heroku 环境变量会使您的应用程序崩溃。 Heroku 自动设置一个可以通过 process.env.PORT 访问的端口。自己设置端口会导致应用崩溃。
尝试编辑您的 server.js 文件
只用const server = http.createServer(process.env.PORT || 3000);
skip normalizePort 启动你的服务器
如果这不能解决问题,那么可能是您缺少所需的环境变量。
-
最后但并非最不重要的一点是,如果以上都没有帮助尝试在
package.json
文件的引擎部分设置节点版本。
像这样
例如:
"name": "myapp",
"description": "a really cool app",
"version": "1.0.0",
"engines":
"node": "12.11.1",
"npm": "6.14.8"
【讨论】:
以上是关于at=错误代码=H10 desc="应用程序崩溃"方法=获取路径="/"的主要内容,如果未能解决你的问题,请参考以下文章
为啥我的 heroku node.js 应用程序给出 at=error code=H10 desc="App crashed" method=GET path="/&qu
Heroku 错误 at=error code=H14 desc="No web processes running" method=GET path="/"
尝试部署 Puppeteer 应用程序 Heroku 后错误代码 = H14 desc="No web processes running"