项目作者: wujohns

项目描述 :
适配腾讯云的 nestjs 部署 serverless component
高级语言: JavaScript
项目地址: git://github.com/wujohns/tencent-sls-nestjs.git
创建时间: 2020-04-02T11:02:10Z
项目社区:https://github.com/wujohns/tencent-sls-nestjs

开源协议:MIT License

下载


tencent-sls-nestjs

适配腾讯云的 nestjs 部署 serverless component

版本说明

该 component 是适配 serverless component 1.0 版本。2020/4/2 官方发布了 serverless component 2.x 版本,相关的格式有所调整,待服务商全面支持 2.x 版本的发布模式后可以考虑使用新的模式发布

serverless.yml 配置

在 serverless.yml 中进行如下配置

  1. # serverless.yml
  2. express:
  3. component: 'tencent-sls-nestjs'
  4. inputs:
  5. region: ap-guangzhou
  6. runtime: Nodejs8.9

nestjs 工程适配

这里给出 express 的适配案例,其他底座可以以此类推

express

  1. // <project-root>/src/app.ts
  2. import * as express from 'express'
  3. import { ExpressAdapter } from '@nestjs/platform-express'
  4. import { NestFactory } from '@nestjs/core'
  5. import { AppModule } from './modules/app.module'
  6. export const getApp = async () => {
  7. const expressApp = express()
  8. const adapter = new ExpressAdapter(expressApp)
  9. const app = await NestFactory.create(AppModule, adapter)
  10. ...
  11. app.init()
  12. return expressApp
  13. }
  1. // <project-root>/src/main.ts - 供本地调试时使用
  2. import * as http from 'http'
  3. import * as config from 'config'
  4. import { getApp } from './app'
  5. const bootstrap = async () => {
  6. const expressApp = await getApp()
  7. const server = http.createServer(expressApp)
  8. server.listen(config.PORT)
  9. }
  10. bootstrap()