CI / build (pull_request) Successful in 59s
Fastify and the Nest adapters bound 127.0.0.1, unreachable from a separate load generator; bind 0.0.0.0 so two-machine benchmarks work.
Adds scale-{green-tea,express} (step-vs-middleware depth sweeps that surfaced the O(n^2)) and green-tea-{bun,deno} (the same app served via serveBun/serveDeno, to benchmark across runtimes).
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
19 lines
896 B
TypeScript
19 lines
896 B
TypeScript
import Fastify from 'fastify';
|
|
|
|
const app = Fastify({ logger: false, keepAliveTimeout: 5000 });
|
|
app.get('/hello', async () => ({ hello: 'world' }));
|
|
app.get('/users/:id', async (req: any) => ({ id: req.params.id }));
|
|
const hook = (n: number) => (req: any, _res: any, done: any) => { req[`s${n}`] = n; done(); };
|
|
app.get('/pipeline', { preHandler: [hook(1), hook(2), hook(3)] }, async (req: any) => ({ hello: 'world', s3: req.s3 }));
|
|
app.post('/validate', {
|
|
schema: { body: { type: 'object', required: ['email'], properties: { email: { type: 'string' } } } },
|
|
}, async (req: any, reply) => {
|
|
const b = req.body;
|
|
if (!b.email.includes('@')) { reply.code(422); return { error: 'invalid' }; }
|
|
return { email: b.email };
|
|
});
|
|
app.listen({ port: 0, host: '0.0.0.0' }, (err, addr) => {
|
|
if (err) { console.error(err); process.exit(1); }
|
|
console.log(`READY ${Number(new URL(addr).port)}`);
|
|
});
|