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)