Skip to content

Commit 571b2b4

Browse files
郎永山郎永山
郎永山
authored and
郎永山
committed
improvement: reduce serverless entry index code
1 parent d4fec50 commit 571b2b4

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,16 @@ $ npm install tencent-serverless-http --save
4545
```
4646
import { NestFactory } from '@nestjs/core';
4747
import { AppModule } from './app.module';
48-
import { Server } from 'http';
4948
import { ExpressAdapter } from '@nestjs/platform-express';
5049
import * as express from 'express';
51-
import { createServer } from 'tencent-serverless-http';
5250
53-
export const bootstrapServer = async (): Promise<Server> => {
51+
export const createApp = async (): Promise<express.Express> => {
5452
const expressApp = express();
5553
const adapter = new ExpressAdapter(expressApp);
5654
const app = await NestFactory.create(AppModule, adapter);
5755
app.enableCors();
5856
await app.init();
59-
return createServer(expressApp)
57+
return expressApp
6058
}
6159
```
6260

lambda-handler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const { proxy } = require('tencent-serverless-http')
1+
const { createServer, proxy } = require('tencent-serverless-http')
22

33
let cachedServer
44
module.exports.handler = async (event, context) => {
5-
const { bootstrapServer } = require.fromParentEnvironment('./dist/index')
5+
const { createApp } = require.fromParentEnvironment('./dist/index')
66
if (!cachedServer) {
7-
const server = await bootstrapServer()
7+
const expressApp = await createApp()
8+
const server = createServer(expressApp)
89
cachedServer = server
910
return proxy(server, event, context, 'PROMISE').promise
1011
} else {

0 commit comments

Comments
 (0)