Skip to content

Commit

Permalink
fix: 避免每次云函数每次调用都重新初始化 nestjs app 实例,降低云函数时间
Browse files Browse the repository at this point in the history
  • Loading branch information
aixgeek authored and yugasun committed Mar 15, 2021
1 parent e0484f9 commit 4fecfb4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/_shims/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ const { createServer, proxy } = require('tencent-serverless-http')
const userSls = path.join(__dirname, '..', 'sls.js')
const getApp = require(userSls)

let app
let server

exports.handler = async (event, context) => {
const nestApp = await getApp()
await nestApp.init()
const app = nestApp.getHttpAdapter().getInstance()

if (!app) {
const nestApp = await getApp()
await nestApp.init()
app = nestApp.getHttpAdapter().getInstance()
}

// attach event and context to request
app.request.__SLS_EVENT__ = event
Expand Down

0 comments on commit 4fecfb4

Please sign in to comment.