Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fastify): Prevent duplicate @fastify/url-data registration #9794

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion packages/api-server/src/plugins/withFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const withFunctions = async (
) => {
const { apiRootPath } = options
// Add extra fastify plugins
fastify.register(fastifyUrlData)
if (!fastify.hasPlugin('@fastify/url-data')) {
await fastify.register(fastifyUrlData)
}

// Fastify v4 must await the fastifyRawBody plugin
// registration to ensure the plugin is ready
Expand Down
4 changes: 3 additions & 1 deletion packages/api-server/src/plugins/withWebServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const withWebServer = async (
fastify: FastifyInstance,
options: WebServerArgs
) => {
fastify.register(fastifyUrlData)
if (!fastify.hasPlugin('@fastify/url-data')) {
await fastify.register(fastifyUrlData)
}

const prerenderedFiles = findPrerenderedHtml()
const indexPath = getFallbackIndexPath()
Expand Down
4 changes: 3 additions & 1 deletion packages/fastify/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export async function redwoodFastifyAPI(
opts: RedwoodFastifyAPIOptions,
done: HookHandlerDoneFunction
) {
fastify.register(fastifyUrlData)
if (!fastify.hasPlugin('@fastify/url-data')) {
await fastify.register(fastifyUrlData)
}
await fastify.register(fastifyRawBody)

// TODO: This should be refactored to only be defined once and it might not live here
Expand Down
4 changes: 3 additions & 1 deletion packages/fastify/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export async function redwoodFastifyGraphQLServer(
// These two plugins are needed to transform a Fastify Request to a Lambda event
// which is used by the RedwoodGraphQLContext and mimics the behavior of the
// api-server withFunction plugin
fastify.register(fastifyUrlData)
if (!fastify.hasPlugin('@fastify/url-data')) {
await fastify.register(fastifyUrlData)
}
await fastify.register(fastifyRawBody)

try {
Expand Down
4 changes: 3 additions & 1 deletion packages/fastify/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export async function redwoodFastifyWeb(
opts: RedwoodFastifyWebOptions,
done: HookHandlerDoneFunction
) {
fastify.register(fastifyUrlData)
if (!fastify.hasPlugin('@fastify/url-data')) {
await fastify.register(fastifyUrlData)
}
const prerenderedFiles = findPrerenderedHtml()

// Serve prerendered HTML directly, instead of the index.
Expand Down
4 changes: 3 additions & 1 deletion packages/web-server/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export async function redwoodFastifyWeb(
opts: RedwoodFastifyWebOptions,
done: HookHandlerDoneFunction
) {
fastify.register(fastifyUrlData)
if (!fastify.hasPlugin('@fastify/url-data')) {
await fastify.register(fastifyUrlData)
}
const prerenderedFiles = findPrerenderedHtml()

// Serve prerendered HTML directly, instead of the index.
Expand Down
Loading