heroku 在部署我的应用程序后,出现“Something is already running on port ___”,然后出现“App Crashed”的H10错误

vohkndzv  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(180)

我将我的NodeJS应用程序部署到Heroku上,没有任何问题,但是当我尝试访问网站时,它没有显示出来,日志说这是因为应用程序崩溃了。在此之前,它说“某些东西已经在端口___上运行(数量变化)”,请参阅下面的完整日志。
我没有在任何地方定义端口,所以我不确定是什么导致了这个问题

2023-04-23T01:48:31.153091+00:00 heroku\[web.1\]: State changed from starting to up
2023-04-23T01:48:31.985212+00:00 app\[web.1\]: (node:94) \[DEP0111\] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
2023-04-23T01:48:31.985224+00:00 app\[web.1\]: (Use `node --trace-deprecation ...` to show where the warning was created)
2023-04-23T01:48:31.994899+00:00 app\[web.1\]: Something is already running on port 54962.
2023-04-23T01:48:32.144102+00:00 heroku\[web.1\]: Process exited with status 0
2023-04-23T01:48:32.215276+00:00 heroku\[web.1\]: State changed from up to crashed
2023-04-23T01:51:22.767165+00:00 heroku\[router\]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.novacancytrans.com request_id=807a004d-266d-4b22-8853-0017d0f41a74 fwd="72.207.46.240" dyno= connect= service= status=503 bytes= protocol=http
2023-04-23T01:51:23.584384+00:00 heroku\[router\]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.novacancytrans.com request_id=d216e51a-ac49-4f54-9816-821b430d18fd fwd="72.207.46.240" dyno= connect= service= status=503 bytes= protocol=http

这是我的包裹。json

{
  "name": "no-vacancy",
  "version": "1.0.0",
  "main": "server.js",
  "engines": {
    "node": "16.x",
    "npm": "8.x"
  },
  "scripts": {
    "start": "npx if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
    "start:prod": "node server.js && cd client/\* & npm run client",
    "start:dev": "node server.js && cd client/\* & npm run client",
    "client": "cd client && npm run start",
    "install": "cd client && npm install",
    "build": "cd client && npm run build",
    "heroku-postbuild": "npm run build"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "bulma": "^0.8.0",
    "concurrently": "^8.0.1",
    "morgan": "^1.9.1"
  },
  "dependencies": {
    "@material-ui/core": "^4.5.1",
    "@material/typography": "^3.1.0",
    "ag-grid-react": "28.2.1",
    "ag-grid-community": "^28.2.1",
    "axios": "^0.19.0",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "classnames": "^2.2.6",
    "concurrently": "^8.0.1",
    "dotenv": "^8.1.0",
    "express": "^4.17.1",
    "formik": "^1.5.8",
    "google-map-react": "^1.1.5",
    "google-maps-react": "^2.0.2",
    "http-proxy-middleware": "^0.20.0",
    "if-env": "^1.0.4",
    "is-empty": "^1.2.0",
    "jsonwebtoken": "^8.5.1",
    "jwt-decode": "^2.2.0",
    "mapbox-gl": "^1.5.0",
    "material-paper": "0.0.8",
    "moment": "^2.24.0",
    "mongodb": "^3.3.2",
    "mongodb-stitch-browser-sdk": "^4.5.0",
    "mongoose": "^5.7.5",
    "mongoose-geojson-schema": "^2.1.3",
    "mongoose-geojson-schemas": "^0.10.13",
    "nodemailer": "^6.8.0",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "react": "^16.10.1",
    "react-datepicker": "^2.9.6",
    "react-dom": "^16.10.2",
    "react-google-maps": "^9.4.5",
    "react-redux": "^7.1.1",
    "react-router-dom": "^5.0.1",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0",
    "semantic-ui-css": "^2.4.1",
    "semantic-ui-react": "^0.88.2",
    "validator": "^11.1.0",
    "yup": "^0.27.0"
  }
}

Procfile

web: npm start

Server.js文件末尾有以下代码:

app.get("\*", function(req, res) {
  res.sendFile(path.join(\__dirname, "./client/build/index.html"));
});
const PORT = process.env.PORT || 5000;

app.listen(PORT, function() {
  console.log(`🌎 ==> API server now on port ${PORT}!`);
});

我尝试的几件事是在终端中运行heroku restart,部署之前的工作分支,因为在我部署之前,网站正在运行。两个都不管用。如果有人知道该怎么做,我会非常感谢帮助!

kgsdhlau

kgsdhlau1#

看起来你在运行两个应用程序。您没有在client中包含npm start的含义,但这可能意味着两个Node服务器(即使client服务器来自某个框架,而不是您自己的代码)。Heroku动态地为您分配一个IP地址。如果你只从你的服务器为你的客户端服务,就不会有冲突。
请参阅thisthisthis和文档。

相关问题