Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update api-server context isolation
  • Loading branch information
Josh-Walker-GM committed Nov 2, 2023
commit 9c4d507107b1af6896e1940b44bea0c70ddeb38b
1 change: 1 addition & 0 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@fastify/http-proxy": "9.2.1",
"@fastify/static": "6.11.2",
"@fastify/url-data": "5.3.1",
"@redwoodjs/context": "6.0.7",
"@redwoodjs/project-config": "6.0.7",
"ansi-colors": "4.1.3",
"chalk": "4.1.2",
Expand Down
1 change: 1 addition & 0 deletions packages/api-server/src/__tests__/fastify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jest.mock('fastify', () => {
return jest.fn(() => {
return {
register: () => {},
addHook: () => {},
}
})
})
Expand Down
7 changes: 7 additions & 0 deletions packages/api-server/src/fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import path from 'path'
import type { FastifyInstance, FastifyServerOptions } from 'fastify'
import Fastify from 'fastify'

import type { GlobalContext } from '@redwoodjs/context'
import { getAsyncStoreInstance } from '@redwoodjs/context'
import { getPaths, getConfig } from '@redwoodjs/project-config'

import type { FastifySideConfigFn } from './types'
Expand Down Expand Up @@ -60,6 +62,11 @@ export const createFastifyInstance = (

const fastify = Fastify(options || config || DEFAULT_OPTIONS)

// Ensure that each request has a unique global context
fastify.addHook('onRequest', (_req, _reply, done) => {
getAsyncStoreInstance().run(new Map<string, GlobalContext>(), done)
})

return fastify
}

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7819,6 +7819,7 @@ __metadata:
"@fastify/http-proxy": 9.2.1
"@fastify/static": 6.11.2
"@fastify/url-data": 5.3.1
"@redwoodjs/context": 6.0.7
"@redwoodjs/project-config": 6.0.7
"@types/aws-lambda": 8.10.119
"@types/lodash": 4.14.195
Expand Down