Skip to content

Commit 803110e

Browse files
Benchmarking (#2)
* adding benchmarking * updating benchmark to sleep before request is made * updating version * updating workflows to add benchmarking * forgot to add examples folder
1 parent 140bc8e commit 803110e

File tree

5 files changed

+299
-33
lines changed

5 files changed

+299
-33
lines changed

.github/workflows/npmpublish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
node-version: 12
1818
- run: npm ci
1919
- run: npm test
20+
- run: npm run benchmark
2021

2122
publish-npm:
2223
needs: build

.github/workflows/pr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ jobs:
1717
node-version: 12
1818
- run: npm ci
1919
- run: npm test
20+
- run: npm run benchmark

examples/baseline.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { fastifyHttpContextPlugin, setContext, getContext } = require('../');
2+
3+
const fastify = require('fastify')();
4+
5+
fastify.register(fastifyHttpContextPlugin, {
6+
defaults: {
7+
user: {
8+
id: 'system'
9+
}
10+
}
11+
});
12+
13+
fastify.addHook('onRequest', (req, reply, done) => {
14+
// overwrite the defaults
15+
setContext('user', { id: 'helloUser' });
16+
done();
17+
});
18+
19+
// this should now get the user id of helloUser instead of the default
20+
fastify.get('/', (req, reply) => {
21+
const user = getContext('user');
22+
reply.code(200).send( { user });
23+
});
24+
25+
fastify.listen(3000, (err, address) => {
26+
if (err) throw err
27+
fastify.log.info(`server listening on ${address}`)
28+
});

0 commit comments

Comments
 (0)