当前位置: 首页 > 知识库问答 >
问题:

修复Heroku退出,状态为1,错误代码H10

欧阳君浩
2023-03-14

我尝试了各种解决方案;使用GitHub作为部署方法,安装NPM包服务,强制清理缓存,重新安装node_modules

错误日志:

2022-01-17T16:20:29.660758 00:00 heroku[web.1]:进程以状态1退出2022-02-01-17:16:20:19.752386 00:00 heroku[web.1]::状态从开始更改为崩溃2022-1-17T15:20:30.611091 00:00 Heloku[router]:at=error code=H10 desc=“App crasted”method=“GET path=/”host=ip-tracker-App.herokuapp。com request_id=a46f3082-43fd-45e9-a049-d1076cad194f fwd=“2.125.111.225”dyno=connect=service=status=503字节=protocol=https 2022-01-17T16:20:31.020509 00:00 heroku[router]:at=error code=H10 desc=“App crash”method=GET path=“/favicon.ico”host=ip-tracker-App.herokuapp。com request_id=c01ac432-ae1c-4994-9fa0-b211a8f00391 fwd=“2.125.111.225”dyno=connect=service=status=503字节=protocol=https

这是我的包裹。json文件:

{
  "name": "ip-address-tracker",
  "version": "1.0.0",
  "description": "*Removed for question*",
  "main": "index.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "start": "node server.js",
    "test": "jest --coverage",
    "devStart": "nodemon server.js"
  },
  "jest": {
    "transform": {
      "^.+\\.[t|j]sx?$": "babel-jest"
    }
  },
  "repository": {
    "type": "git",
    "url": "*Removed for question*"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "*Removed for question*",
  },
  "homepage": "*Removed for question*",
  "dependencies": {
    "dotenv": "^10.0.0",
    "express": "^4.17.2",
    "jest": "^27.4.7",
    "serve": "^13.0.2"
  },
  "devDependencies": {
    "@babel/core": "^7.16.7",
    "@babel/preset-env": "^7.16.8",
    "babel-jest": "^27.4.6",
    "nodemon": "^2.0.15",
    "regenerator-runtime": "^0.13.9"
  }
}

我的server.js文件:

const express = require('express');
const app = express();
const dotenv = require('dotenv');
const result = dotenv.config();

if (result.error) {
    throw result.error;
}

const PORT = process.env.PORT || 3000;

app.use(express.static('public'));

app.listen(PORT, () => {
    console.log(`App is listening on ${PORT}.`);
});

我添加了以下Procfile:

web: npm start

共有1个答案

卢鸿博
2023-03-14

我在您的服务上看到一个问题,如果您想提供像dist这样的html文件,请尝试这样做

app.use('/', serveStatic(path.join(__dirname, '/public')))

如果目的是传递图像

app.use(express.static(path.join(__dirname,'public')))
 类似资料: