feat(bench): add NestJS (platform-express + platform-fastify) servers

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-06 23:30:40 -05:00
1 parent 7593d1425a
commit fe1831a80a
7 files changed
+737 -1

No files matched your search

+20
View File
@@ -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'); }
}
+17
View File
@@ -0,0 +1,17 @@
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import express from 'express';
import { BenchModule } from './_nest-shared';
async function main() {
const inst = express();
inst.disable('x-powered-by');
inst.set('etag', false);
const app = await NestFactory.create(BenchModule, new ExpressAdapter(inst), { logger: false });
await app.listen(0, '127.0.0.1');
const server = app.getHttpServer();
server.keepAliveTimeout = 5000; // parity (works on Node http.Server after listen)
console.log(`READY ${server.address().port}`);
}
main().catch((e) => { console.error(e); process.exit(1); });
+13
View File
@@ -0,0 +1,13 @@
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { BenchModule } from './_nest-shared';
async function main() {
const adapter = new FastifyAdapter({ logger: false, keepAliveTimeout: 5000 }); // parity via constructor
const app = await NestFactory.create<NestFastifyApplication>(BenchModule, adapter, { logger: false });
await app.listen(0, '127.0.0.1');
const server = app.getHttpServer();
console.log(`READY ${(server.address() as any).port}`);
}
main().catch((e) => { console.error(e); process.exit(1); });