Created
July 18, 2022 18:37
-
-
Save airscholar/836b361691a70b0cc00068e3b04eb225 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ExpressAdapter } from '@nestjs/platform-express'; | |
| import { NestFactory } from '@nestjs/core'; | |
| import { AppModule } from './app.module'; | |
| import { Context, Handler } from 'aws-lambda'; | |
| import { INestApplication } from '@nestjs/common'; | |
| import { Express } from 'express'; | |
| import * as express from 'express'; | |
| import { createServer, proxy } from 'aws-serverless-express'; | |
| import { Server } from 'http'; | |
| let server: Server; | |
| async function createExpressApp( | |
| expressApp: Express, | |
| ): Promise<INestApplication> { | |
| const app = await NestFactory.create( | |
| AppModule, | |
| new ExpressAdapter(expressApp), | |
| ); | |
| return app; | |
| } | |
| async function bootstrap() { | |
| const expressApp = express(); | |
| const app = await createExpressApp(expressApp); | |
| await app.init(); | |
| return createServer(expressApp); | |
| } | |
| export const handler: Handler = async (event: any, context: Context) => { | |
| server = server ?? (await bootstrap()); | |
| return proxy(server, event, context, 'PROMISE').promise; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment