diff --git a/packages/api-server/src/createServer.ts b/packages/api-server/src/createServer.ts index 600474d3e7b7..5eabb4322a88 100644 --- a/packages/api-server/src/createServer.ts +++ b/packages/api-server/src/createServer.ts @@ -124,7 +124,7 @@ export async function createServer(options: CreateServerOptions = {}) { }) if (graphqlFunctionPath) { - const { redwoodFastifyGraphQLServer } = await import('./plugins/graphql') + const { redwoodFastifyGraphQLServer } = await import('./plugins/graphql.js') // This comes from a babel plugin that's applied to api/dist/functions/graphql.{ts,js} in user projects const { __rw_graphqlOptions } = await import( `file://${graphqlFunctionPath}` diff --git a/packages/api-server/src/plugins/graphql.ts b/packages/api-server/src/plugins/graphql.ts index c8b8fd6f1dec..779bd44385a8 100644 --- a/packages/api-server/src/plugins/graphql.ts +++ b/packages/api-server/src/plugins/graphql.ts @@ -102,22 +102,24 @@ export async function redwoodFastifyGraphQLServer( return reply } + const graphqlEndpoint = trimSlashes(yoga.graphqlEndpoint) + const routePaths = ['', '/health', '/readiness', '/stream'] for (const routePath of routePaths) { fastify.route({ - url: `${redwoodOptions.apiRootPath}${yoga.graphqlEndpoint}${routePath}`, + url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`, method, handler: (req, reply) => graphQLYogaHandler(req, reply), }) } fastify.addHook('onReady', (done) => { - console.info(`GraphQL Yoga Server endpoint at ${yoga.graphqlEndpoint}`) + console.info(`GraphQL Yoga Server endpoint at ${graphqlEndpoint}`) console.info( - `GraphQL Yoga Server Health Check endpoint at ${yoga.graphqlEndpoint}/health` + `GraphQL Yoga Server Health Check endpoint at ${graphqlEndpoint}/health` ) console.info( - `GraphQL Yoga Server Readiness endpoint at ${yoga.graphqlEndpoint}/readiness` + `GraphQL Yoga Server Readiness endpoint at ${graphqlEndpoint}/readiness` ) done() @@ -126,3 +128,7 @@ export async function redwoodFastifyGraphQLServer( console.log(e) } } + +function trimSlashes(path: string) { + return path.replace(/^\/|\/$/g, '') +}