[英]Cannot deploy my reactjs webpack application on google app engine
[英]Cannot deploy correctly NestJS on Google App Engine
我正在尝试在 Google App Engine 上部署我的 Nest.js,但无法成功部署...
复制:
nest new my-project
在src/main.ts
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 || 8080);
}
bootstrap();
在package.json
{
"name": "nest-gcloud-test",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"main": "dist/main.js",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "npm run start:dev",
"start:dev": "node dist/main --watch",
"start:debug": "node dist/main --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/common": "^7.6.13",
"@nestjs/core": "^7.6.13",
"@nestjs/platform-express": "^7.6.13",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.6"
},
"devDependencies": {
"@nestjs/cli": "^7.5.6",
"@nestjs/schematics": "^7.2.7",
"@nestjs/testing": "^7.6.13",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-jest": "^26.5.2",
"ts-loader": "^8.0.17",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
在app.yaml
runtime: nodejs12
并部署
gcloud app deploy
一段时间后,GAE 日志显示 Nest 应用程序已成功启动,但 GAE 立即关闭并显示以下消息:
[start] 2021/03/24 20:31:36.643972 No entrypoint specified, using default entrypoint: /serve
[start] 2021/03/24 20:31:36.647170 Starting app
[start] 2021/03/24 20:31:36.647513 Executing: /bin/sh -c exec /serve
[start] 2021/03/24 20:31:36.658103 Waiting for network connection open. Subject:"app/invalid" Address:127.0.0.1:8080
[start] 2021/03/24 20:31:36.660574 Waiting for network connection open. Subject:"app/valid" Address:127.0.0.1:8081
[serve] 2021/03/24 20:31:36.682824 Serve started.
[serve] 2021/03/24 20:31:36.683836 Args: {runtimeLanguage:nodejs runtimeName:nodejs12 memoryMB:256 positional:[]}
[serve] 2021/03/24 20:31:36.686634 Running /bin/sh -c exec npm run start:dev
> nest-gcloud-test@0.0.1 start:dev /workspace
> node dist/main --watch
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[NestFactory] [39m[32mStarting Nest application...[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[InstanceLoader] [39m[32mAppModule dependencies initialized[39m[38;5;3m +45ms[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[RoutesResolver] [39m[32mAppController {}:[39m[38;5;3m +6ms[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[RouterExplorer] [39m[32mMapped {, GET} route[39m[38;5;3m +3ms[39m
[32m[Nest] 31 - [39m03/24/2021, 8:31:39 PM [38;5;3m[NestApplication] [39m[32mNest application successfully started[39m[38;5;3m +2ms[39m
[start] 2021/03/24 20:32:53.970253 Quitting on terminated signal
[start] 2021/03/24 20:32:53.970940 Start program failed: failed to detect app after start: ForAppStart(): [aborted, context canceled. subject:"app/invalid" Timeout:30m0s, attempts:120069 aborted, context canceled. subject:"app/valid" Timeout:30m0s, attempts:120115]
stderr
上没有错误日志。
但是我可以成功部署一个简单的 http 服务器,如下所示:
app.js
const http = require('http');
const server = http.createServer((req, res) => {
res.end(`Hello World\n`);
});
server.listen(process.env.PORT || 8080, () => {
console.log('app started');
});
app.yaml
runtime: nodejs12
package.json
{
"name": "appengine",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
运行gcloud app deploy
成功,没有问题。
任何帮助表示赞赏。
将"gcp-build": "npm run build"
添加到package.json
然后它现在工作正常,没有任何问题。
解决方案将“gcp-build”:“npm run build”添加到package.json
然后它现在工作正常,没有任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.