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(server): don't mix async and callback styles #9931

Merged
merged 1 commit into from
Jan 29, 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
14 changes: 2 additions & 12 deletions packages/adapters/fastify/web/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import httpProxy from '@fastify/http-proxy'
import fastifyStatic from '@fastify/static'
import fastifyUrlData from '@fastify/url-data'
import fg from 'fast-glob'
import type {
FastifyInstance,
FastifyReply,
FastifyRequest,
HookHandlerDoneFunction,
} from 'fastify'
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify'

import { getPaths } from '@redwoodjs/project-config'

Expand All @@ -22,8 +17,7 @@ export { coerceRootPath, RedwoodFastifyWebOptions }

export async function redwoodFastifyWeb(
fastify: FastifyInstance,
opts: RedwoodFastifyWebOptions,
done: HookHandlerDoneFunction
opts: RedwoodFastifyWebOptions
) {
const { redwoodOptions, flags } = resolveOptions(opts)

Expand Down Expand Up @@ -53,8 +47,6 @@ export async function redwoodFastifyWeb(
// but TS doesn't know that so it complains about `apiUrl` being undefined
// in `fastify.all(...)` below. So we have to do this check for now
if (redwoodOptions.apiUrl && flags.shouldRegisterApiUrl) {
fastify.log.warn("apiUrl is relative but there's no proxy target")

const apiUrlHandler = (_req: FastifyRequest, reply: FastifyReply) => {
reply.code(200)
reply.send({
Expand Down Expand Up @@ -113,6 +105,4 @@ export async function redwoodFastifyWeb(
reply.code(404)
return reply.send('Not Found')
})

done()
}
6 changes: 1 addition & 5 deletions packages/api-server/src/createServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
FastifyListenOptions,
FastifyServerOptions,
FastifyInstance,
HookHandlerDoneFunction,
} from 'fastify'
import fastifyRawBody from 'fastify-raw-body'

Expand Down Expand Up @@ -312,8 +311,7 @@ export interface RedwoodFastifyAPIOptions {

export async function redwoodFastifyFunctions(
fastify: FastifyInstance,
opts: RedwoodFastifyAPIOptions,
done: HookHandlerDoneFunction
opts: RedwoodFastifyAPIOptions
) {
fastify.register(fastifyUrlData)
await fastify.register(fastifyRawBody)
Expand All @@ -332,6 +330,4 @@ export async function redwoodFastifyFunctions(
ignore: ['**/dist/functions/graphql.js'],
},
})

done()
}
6 changes: 1 addition & 5 deletions packages/api-server/src/plugins/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import fg from 'fast-glob'
import type {
FastifyInstance,
HTTPMethods,
HookHandlerDoneFunction,
FastifyReply,
FastifyRequest,
} from 'fastify'
Expand Down Expand Up @@ -35,8 +34,7 @@ export interface RedwoodFastifyGraphQLOptions {
*/
export async function redwoodFastifyGraphQLServer(
fastify: FastifyInstance,
options: RedwoodFastifyGraphQLOptions,
done: HookHandlerDoneFunction
options: RedwoodFastifyGraphQLOptions
) {
// 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
Expand Down Expand Up @@ -126,8 +124,6 @@ export async function redwoodFastifyGraphQLServer(

done()
})

done()
} catch (e) {
console.log(e)
}
Expand Down
7 changes: 2 additions & 5 deletions packages/fastify/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastifyUrlData from '@fastify/url-data'
import type { FastifyInstance, HookHandlerDoneFunction } from 'fastify'
import type { FastifyInstance } from 'fastify'
import fastifyRawBody from 'fastify-raw-body'

import type { GlobalContext } from '@redwoodjs/context'
Expand All @@ -11,8 +11,7 @@ import type { RedwoodFastifyAPIOptions } from './types'

export async function redwoodFastifyAPI(
fastify: FastifyInstance,
opts: RedwoodFastifyAPIOptions,
done: HookHandlerDoneFunction
opts: RedwoodFastifyAPIOptions
) {
if (!fastify.hasPlugin('@fastify/url-data')) {
await fastify.register(fastifyUrlData)
Expand Down Expand Up @@ -41,6 +40,4 @@ export async function redwoodFastifyAPI(
fastify.all(`${apiRootPath}:routeName`, lambdaRequestHandler)
fastify.all(`${apiRootPath}:routeName/*`, lambdaRequestHandler)
await loadFunctionsFromDist()

done()
}
Loading