NodeJS 当我尝试部署nestjs时,elastic beanstalk get error 502 Bad Gateway

oprakyz7  于 2023-04-29  发布在  Node.js
关注(0)|答案(1)|浏览(125)

25
我在管理一个巢穴。Amazon Elastic Beanstalk上的js应用程序和我的环境被成功创建,但是当我通过Amazon创建的URL进入我的环境时,我收到了一个502 Bad Gateway nginx/1。6.2错误。我相信Elastic Beanstalk运行并且它不工作,(错误消息):所有示例上的服务已降级。
以下服务未运行:网。
mypackage.json配置

{
  "name": "demo",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/class-validator": "^0.13.4",
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/mongoose": "^9.2.2",
    "@nestjs/platform-express": "^9.0.0",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.0",
    "mongoose": "^7.0.2",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.2.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.0.0",
    "@nestjs/schematics": "^9.0.0",
    "@nestjs/testing": "^9.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "29.2.4",
    "@types/node": "18.11.18",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "29.3.1",
    "prettier": "^2.3.2",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "29.0.3",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.1.1",
    "typescript": "^4.7.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

虽然我尝试设置端口env在变量是8080,但它不'工作,我认为它一些错误的东西在我的代码设置

py49o6xq

py49o6xq1#

1 -在项目的根目录中创建Procfile并添加以下内容。此文件将告诉Elastic Beanstalk引擎运行定义的命令。
web:npm run deploy 2 -添加一个“deploy”脚本到你的包。json文件

"scripts": {
  ...
  "deploy": "npm ci && npm run build && npm run start:prod"
  ...
}

3 -确保你的应用可以列表到PORT环境变量。

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
​
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(process.env.PORT || 3000);
}
bootstrap();

相关问题