[英]How to publish Nestjs api in Google App Engine?
我正在嘗試將我的 nestjs api 放入 Google App Engine,但我仍然有錯誤。 我首先使用谷歌 sdk 創建了我的谷歌雲項目,編輯我的代碼如下:
main.ts:
import {NestFactory} from '@nestjs/core';
import {DocumentBuilder, SwaggerModule} from '@nestjs/swagger';
import {AppModule} from './app.module';
import {ValidationPipe} from "@nestjs/common";
import * as cookieParser from 'cookie-parser';
import * as helmet from 'helmet';
import * as Express from 'express';
import { ExpressAdapter } from '@nestjs/platform-express';
const server = Express();
server.get('/',(req,res) => res.send('ok'));
server.get('/_ah/health',(req,res) => res.send('ok'));
async function bootstrap() {
const app = await NestFactory.create(AppModule, new ExpressAdapter(server), { cors: true });
//Validation
app.useGlobalPipes(new ValidationPipe({
whitelist: true,
}));
//Swagger
const config = new DocumentBuilder()
.setTitle('Title')
.setDescription('Description')
.addBearerAuth()
.setVersion('2.0')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('doc', app, document);
//Use Cookies
app.use(cookieParser());
//Security
//1 - Helmet
app.use(helmet());
//2 - CORS :/
app.enableCors();
await app.listen(8080);
}
bootstrap();
package.json:
{
"name": "name",
"version": "2.0.0",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"main": "dist/main.js",
"engines": {
"node": ">=8.0.0"
},
"scripts": {
"build": "nest build",
"prepare": "npm run gcp-build",
"pretest": "npm run gcp-build",
"posttest": "npm run lint",
"prebuild": "rimraf dist",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "node ./index.js",
"start:dev": "nodemon",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "tslint -p .",
"test": "mocha test/*.test.js --exit",
"compodoc": "npx compodoc -p tsconfig.app.json src -n \"Elengui REST API 2.0\" -r 3001 --theme readthedocs --hideGenerator",
"gcp-build": "npm run build",
"deploy": "gcloud app deploy"
},
"dependencies": {
"@hapi/joi": "^17.1.1",
"@nestjs/common": "^7.5.1",
"@nestjs/config": "^0.6.3",
"@nestjs/core": "^7.5.1",
"@nestjs/jwt": "^7.2.0",
"@nestjs/mapped-types": "^0.3.0",
"@nestjs/passport": "^7.1.5",
"@nestjs/platform-express": "^7.5.1",
"@nestjs/swagger": "^4.7.13",
"@nestjs/throttler": "^1.1.3",
"@nestjs/typeorm": "^7.1.5",
"@types/bcrypt": "^3.0.0",
"@types/cookie-parser": "^1.4.2",
"@types/hapi__joi": "^17.1.6",
"@types/nodemailer": "^6.4.0",
"@types/passport": "^1.0.6",
"@types/passport-jwt": "^3.0.4",
"@types/passport-local": "^1.0.33",
"bcrypt": "^5.0.0",
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"cookie-parser": "^1.4.5",
"crypto-random-string": "^3.3.1",
"csurf": "^1.11.0",
"hbs": "^4.1.1",
"helmet": "^4.4.1",
"mysql2": "^2.2.5",
"nodemailer": "^6.5.0",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"path": "^0.12.7",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.3",
"swagger-ui-express": "^4.1.6",
"typeorm": "^0.2.31",
"express": "^4.16.3"
},
"devDependencies": {
"@nestjs/cli": "^7.5.4",
"@nestjs/schematics": "^7.1.3",
"@nestjs/testing": "^7.5.1",
"@types/express": "^4.16.0",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.6.1",
"@typescript-eslint/parser": "^4.6.1",
"eslint": "^7.12.1",
"eslint-config-prettier": "7.2.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.6.3",
"prettier": "^2.1.2",
"supertest": "^6.0.0",
"ts-jest": "^26.4.3",
"ts-loader": "^8.0.8",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.0.5",
"mocha": "^8.0.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
當我嘗試部署項目時,我收到此錯誤:
> nest build
sh: 1: nest: not found
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! elengui-api@2.0.0 build: `rm -rf dist && tsc -p tsconfig.build.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the elengui-api@2.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我已經完成了“npm install”,但腳本似乎無法識別命令嵌套。 關於發生了什么的任何想法? 提前致謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.