Skip to content

Commit

Permalink
chore(readme): update references to deprecated name (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblcuk authored Jan 6, 2025
1 parent 5764d45 commit 2844e6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ npm i @fastify/request-context
Next, set up the plugin:

```js
const { fastifyRequestContextPlugin } = require('@fastify/request-context')
const { fastifyRequestContext } = require('@fastify/request-context')
const fastify = require('fastify');

fastify.register(fastifyRequestContextPlugin);
fastify.register(fastifyRequestContext);
```

Or customize hook and default store values:

```js
const { fastifyRequestContextPlugin } = require('@fastify/request-context')
const { fastifyRequestContext } = require('@fastify/request-context')
const fastify = require('fastify');

fastify.register(fastifyRequestContextPlugin, {
fastify.register(fastifyRequestContext, {
hook: 'preValidation',
defaultStoreValues: {
user: { id: 'system' }
Expand All @@ -48,10 +48,10 @@ fastify.register(fastifyRequestContextPlugin, {
Default store values can be set through a function as well:

```js
const { fastifyRequestContextPlugin } = require('@fastify/request-context')
const { fastifyRequestContext } = require('@fastify/request-context')
const fastify = require('fastify');

fastify.register(fastifyRequestContextPlugin, {
fastify.register(fastifyRequestContext, {
defaultStoreValues: request => ({
log: request.log.child({ foo: 123 })
})
Expand All @@ -71,11 +71,11 @@ Request context (with methods `get` and `set`) is exposed by library itself, but
For instance:

```js
const { fastifyRequestContextPlugin, requestContext } = require('@fastify/request-context')
const { fastifyRequestContext, requestContext } = require('@fastify/request-context')
const fastify = require('fastify');

const app = fastify({ logger: true })
app.register(fastifyRequestContextPlugin, {
app.register(fastifyRequestContext, {
defaultStoreValues: {
user: { id: 'system' }
},
Expand Down
12 changes: 6 additions & 6 deletions test/internal/appInitializer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict'

const fastify = require('fastify')
const { fastifyRequestContextPlugin } = require('../..')
const { fastifyRequestContext } = require('../..')

function initAppGet(endpoint) {
const app = fastify({ logger: true })
app.register(fastifyRequestContextPlugin)
app.register(fastifyRequestContext)

app.get('/', endpoint)
return app
}

function initAppPost(endpoint) {
const app = fastify({ logger: true })
app.register(fastifyRequestContextPlugin)
app.register(fastifyRequestContext)

app.post('/', endpoint)

Expand All @@ -22,7 +22,7 @@ function initAppPost(endpoint) {

function initAppPostWithPrevalidation(endpoint) {
const app = fastify({ logger: true })
app.register(fastifyRequestContextPlugin, { hook: 'preValidation' })
app.register(fastifyRequestContext, { hook: 'preValidation' })

const preValidationFn = (req, reply, done) => {
const requestId = Number.parseInt(req.body.requestId)
Expand All @@ -42,7 +42,7 @@ function initAppPostWithPrevalidation(endpoint) {

function initAppPostWithAllPlugins(endpoint, requestHook) {
const app = fastify({ logger: true })
app.register(fastifyRequestContextPlugin, { hook: requestHook })
app.register(fastifyRequestContext, { hook: requestHook })

app.addHook('onRequest', (req, reply, done) => {
req.requestContext.set('onRequest', 'dummy')
Expand Down Expand Up @@ -87,7 +87,7 @@ function initAppPostWithAllPlugins(endpoint, requestHook) {

function initAppGetWithDefaultStoreValues(endpoint, defaultStoreValues) {
const app = fastify({ logger: true })
app.register(fastifyRequestContextPlugin, {
app.register(fastifyRequestContext, {
defaultStoreValues,
})

Expand Down

0 comments on commit 2844e6a

Please sign in to comment.