feat(bench): green-tea/express/fastify/raw-http servers with parity controls
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+101
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import Fastify from 'fastify';
|
||||
|
||||
const app = Fastify({ logger: false });
|
||||
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 }, (err, addr) => {
|
||||
if (err) { console.error(err); process.exit(1); }
|
||||
(app.server as any).keepAliveTimeout = 5000;
|
||||
console.log(`READY ${Number(new URL(addr).port)}`);
|
||||
});
|
||||
Reference in new issue
Block a user