Skip to content

Commit

Permalink
Add support for Fastify v3 (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 20, 2020
1 parent 7be0fc5 commit 6043c1f
Show file tree
Hide file tree
Showing 5 changed files with 583 additions and 267 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Request Tracer - Express & Koa middlewares and Fastify & Hapi plugins for CLS-ba

Automatically generates a UUID V1 value as the id for each request and stores it in `AsyncLocalStorage` (CLS core API, see [this blog post](https://itnext.io/one-node-js-cls-api-to-rule-them-all-1670ac66a9e8)). Optionally, if the request contains `X-Request-Id` header, uses its value instead. Allows to obtain the generated request id anywhere in your routes later and use it for logging or any other purposes.

Tested and works fine with Express v4, Fastify v2, Koa (both v1 and v2), and Hapi v18.
Tested and works fine with Express v4, Fastify v2 and v3, Koa v1 and v2, and Hapi v18.

## Supported Node.js versions

Expand Down Expand Up @@ -129,7 +129,7 @@ async function find (entityId) {

### Legacy Fastify middleware

There is a connect-style middleware available for Fastify, but it is deprecated and may be removed in one of upcoming releases. If you happen to use it in your application, you should migrate to the Fastify plugin.
There is a connect-style middleware available for Fastify v2, but it is deprecated and may be removed in one of upcoming releases. If you happen to use it in your application, you should migrate to the Fastify plugin.

```js
fastify.use(rTracer.fastifyMiddleware())
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"@hapi/hapi": "^19.1.1",
"coveralls": "^3.1.0",
"express": "^4.17.1",
"fastify": "^2.14.1",
"fastify": "^3.2.1",
"fastifyv2": "npm:fastify@^2.14.1",
"jest": "^26.0.1",
"koa": "^2.12.0",
"koav1": "npm:koa@^1.7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/rtracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const fastifyPlugin = (fastify, options, next) => {
requestId = requestId || uuidv1()

als.run(requestId, () => {
wrapHttpEmitters(request.raw, reply.res)
wrapHttpEmitters(request.raw, reply.raw || reply.res)
done()
})
})
Expand Down

0 comments on commit 6043c1f

Please sign in to comment.