Skip to content

Commit ec34eb9

Browse files
committed
Support for NestJS
1 parent 282e15a commit ec34eb9

File tree

4 files changed

+80
-33
lines changed

4 files changed

+80
-33
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The list of supported frameworks matches [in-process-request](https://github.com
1010
* Express.js v5
1111
* Apollo Server v2
1212
* Hapi v19 (only supported in `nodejs12.x` runtime)
13+
* NestJS v7
1314
* Connect v3
1415
* Koa v2
1516

@@ -136,3 +137,41 @@ module.exports = { handler }
136137
```
137138

138139
If the above file in your Lambda source was called `index.js` then the name of the handler in the Lambda configuration is `index.handler`
140+
141+
### NestJS
142+
143+
This example is in Typescript
144+
145+
```typescript
146+
import lambdaRequestHandler from 'lambda-request-handler'
147+
148+
import { NestFactory } from '@nestjs/core';
149+
import { Module, Get, Controller } from '@nestjs/common';
150+
import { NestExpressApplication } from '@nestjs/platform-express';
151+
152+
@Controller()
153+
class AppController {
154+
@Get()
155+
render() {
156+
return { hello: 'world' };
157+
}
158+
}
159+
160+
@Module({
161+
imports: [],
162+
controllers: [AppController],
163+
})
164+
class AppModule {}
165+
166+
const getApp = async () => {
167+
const app = await NestFactory.create<NestExpressApplication>(AppModule);
168+
169+
return await lambdaRequestHandler.nestHandler(app);
170+
}
171+
172+
const handler = lambdaRequestHandler.deferred(getApp);
173+
174+
exports = { handler }
175+
```
176+
177+
If the above file in your Lambda source was called `index.ts`, compiled to `index.js` then the name of the handler in the Lambda configuration is `index.handler`

package-lock.json

+32-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"handler",
2222
"express",
2323
"expressjs",
24+
"hapi",
25+
"nestjs",
2426
"koa",
2527
"connect",
2628
"http",
@@ -34,22 +36,22 @@
3436
"main": "./dist/compile/lambda",
3537
"types": "./dist/compile/lambda.d.ts",
3638
"dependencies": {
37-
"in-process-request": "^0.1.0",
39+
"in-process-request": "^0.2.1",
3840
"isutf8": "^3.0.0"
3941
},
4042
"devDependencies": {
4143
"@types/compression": "^1.7.0",
4244
"@types/cookie-parser": "^1.4.2",
4345
"@types/express": "^4.17.6",
44-
"@types/jest": "^25.2.1",
45-
"@types/node": "^14.0.1",
46+
"@types/jest": "^25.2.3",
47+
"@types/node": "^14.0.4",
4648
"compression": "^1.7.4",
4749
"cookie-parser": "^1.4.5",
48-
"ejs": "^3.1.2",
50+
"ejs": "^3.1.3",
4951
"express": "^4.17.1",
5052
"jest": "^26.0.1",
51-
"ts-jest": "^25.5.1",
53+
"ts-jest": "^26.0.0",
5254
"ts-node": "^8.10.1",
53-
"typescript": "^3.9.2"
55+
"typescript": "^3.9.3"
5456
}
5557
}

src/lambda.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ const handlerBuilder = (appFn: PromiseFactory<RequestListener>): handler.APIGate
4646
const handler = (app: RequestListener) => handlerBuilder(() => Promise.resolve(app));
4747
handler.deferred = handlerBuilder;
4848
handler.HapiListener = inProcessRequestHandler.HapiListener;
49+
handler.nestHandler = inProcessRequestHandler.nestHandler;
4950

5051
export = handler;

0 commit comments

Comments
 (0)