feat(bench): add NestJS (platform-express + platform-fastify) servers
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
7 files changed
+737
-1
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { Module, Controller, Get, Post, Param, Body, HttpException, MiddlewareConsumer, NestModule } from '@nestjs/common';
|
||||
|
||||
@Controller()
|
||||
export class BenchController {
|
||||
@Get('hello') hello() { return { hello: 'world' }; }
|
||||
@Get('users/:id') user(@Param('id') id: string) { return { id }; }
|
||||
@Get('pipeline') pipeline() { return { hello: 'world', s3: 3 }; }
|
||||
@Post('validate') validate(@Body() b: any) {
|
||||
if (!(b && typeof b.email === 'string' && b.email.includes('@'))) throw new HttpException({ error: 'invalid' }, 422);
|
||||
return { email: b.email };
|
||||
}
|
||||
}
|
||||
|
||||
// pipeline parity: 3 middleware hops on /pipeline (approximation of 3 @Steps), adapter-agnostic
|
||||
const mw = (_n: number) => (_req: any, _res: any, next: any) => next();
|
||||
|
||||
@Module({ controllers: [BenchController] })
|
||||
export class BenchModule implements NestModule {
|
||||
configure(c: MiddlewareConsumer) { c.apply(mw(1), mw(2), mw(3)).forRoutes('pipeline'); }
|
||||
}
|
||||
Reference in new issue
Block a user