From 1e90d1e706e5c8d76aa82d4666f379aa4a6228f0 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:40:51 +0000 Subject: [PATCH 1/4] update api-server --- packages/api-server/src/plugins/withFunctions.ts | 4 +++- packages/api-server/src/plugins/withWebServer.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/api-server/src/plugins/withFunctions.ts b/packages/api-server/src/plugins/withFunctions.ts index d985fcbb0697..316411f2f68a 100644 --- a/packages/api-server/src/plugins/withFunctions.ts +++ b/packages/api-server/src/plugins/withFunctions.ts @@ -13,7 +13,9 @@ const withFunctions = async ( ) => { const { apiRootPath } = options // Add extra fastify plugins - fastify.register(fastifyUrlData) + if (!fastify.hasPlugin('@fastify/url-data')) { + fastify.register(fastifyUrlData) + } // Fastify v4 must await the fastifyRawBody plugin // registration to ensure the plugin is ready diff --git a/packages/api-server/src/plugins/withWebServer.ts b/packages/api-server/src/plugins/withWebServer.ts index 98c5b9d8ce6c..5d59855e1947 100644 --- a/packages/api-server/src/plugins/withWebServer.ts +++ b/packages/api-server/src/plugins/withWebServer.ts @@ -28,7 +28,9 @@ const withWebServer = async ( fastify: FastifyInstance, options: WebServerArgs ) => { - fastify.register(fastifyUrlData) + if (!fastify.hasPlugin('@fastify/url-data')) { + fastify.register(fastifyUrlData) + } const prerenderedFiles = findPrerenderedHtml() const indexPath = getFallbackIndexPath() From ace1128be7b57c1baa2879264f2b6bde2045811f Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:41:20 +0000 Subject: [PATCH 2/4] update fastify --- packages/fastify/src/api.ts | 4 +++- packages/fastify/src/graphql.ts | 4 +++- packages/fastify/src/web.ts | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/fastify/src/api.ts b/packages/fastify/src/api.ts index 47e5205d01e0..d060edbd3656 100644 --- a/packages/fastify/src/api.ts +++ b/packages/fastify/src/api.ts @@ -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 diff --git a/packages/fastify/src/graphql.ts b/packages/fastify/src/graphql.ts index bf564f33aace..b3d1ef5d06b1 100644 --- a/packages/fastify/src/graphql.ts +++ b/packages/fastify/src/graphql.ts @@ -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 { diff --git a/packages/fastify/src/web.ts b/packages/fastify/src/web.ts index 93bd0cc89e7e..b8d1bbac26e7 100644 --- a/packages/fastify/src/web.ts +++ b/packages/fastify/src/web.ts @@ -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. From 790141ea3177d8ae92c4907a74e2e6a38c52e99b Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:42:22 +0000 Subject: [PATCH 3/4] update web-server --- packages/web-server/src/web.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/web-server/src/web.ts b/packages/web-server/src/web.ts index 8b115880335a..1a60ee88efb2 100644 --- a/packages/web-server/src/web.ts +++ b/packages/web-server/src/web.ts @@ -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. From 297232a4f11ca3200451f063d90b4c0e74e0d151 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:51:16 +0000 Subject: [PATCH 4/4] consistently await plugin registration --- packages/api-server/src/plugins/withFunctions.ts | 2 +- packages/api-server/src/plugins/withWebServer.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api-server/src/plugins/withFunctions.ts b/packages/api-server/src/plugins/withFunctions.ts index 316411f2f68a..dd0a2006bb79 100644 --- a/packages/api-server/src/plugins/withFunctions.ts +++ b/packages/api-server/src/plugins/withFunctions.ts @@ -14,7 +14,7 @@ const withFunctions = async ( const { apiRootPath } = options // Add extra fastify plugins if (!fastify.hasPlugin('@fastify/url-data')) { - fastify.register(fastifyUrlData) + await fastify.register(fastifyUrlData) } // Fastify v4 must await the fastifyRawBody plugin diff --git a/packages/api-server/src/plugins/withWebServer.ts b/packages/api-server/src/plugins/withWebServer.ts index 5d59855e1947..d265c428159f 100644 --- a/packages/api-server/src/plugins/withWebServer.ts +++ b/packages/api-server/src/plugins/withWebServer.ts @@ -29,7 +29,7 @@ const withWebServer = async ( options: WebServerArgs ) => { if (!fastify.hasPlugin('@fastify/url-data')) { - fastify.register(fastifyUrlData) + await fastify.register(fastifyUrlData) } const prerenderedFiles = findPrerenderedHtml()