From 481c6e3521efa917378a6af22739564c2af63bfe Mon Sep 17 00:00:00 2001 From: RiveN <61630074+rivenintech@users.noreply.github.com> Date: Sat, 7 Jun 2025 19:40:00 +0200 Subject: [PATCH] fix: CORS execution order --- src/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 00c831d..1b9102c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,6 +58,14 @@ const graphQLServerOptions: GraphQLServerOptions = { const app = new Hono<{ Bindings: Bindings }>() +if (graphQLServerOptions.cors) { + if (typeof graphQLServerOptions.cors === 'boolean') { + app.use(cors()) + } else { + app.use(cors(graphQLServerOptions.cors)) + } +} + app.all(graphQLServerOptions.baseEndpoint, (context) => { return Apollo(context, graphQLServerOptions) }) @@ -69,14 +77,6 @@ app.all('*', async (c) => { return new Response('Not found', { status: 404 }) }) -if (graphQLServerOptions.cors) { - if (typeof graphQLServerOptions.cors === 'boolean') { - app.use(cors()) - } else { - app.use(cors(graphQLServerOptions.cors)) - } -} - app.onError((err, c) => { console.error(err) return c.text('Something went wrong', 500)