Skip to content

Commit

Permalink
apollo-server-koa: Respond to OPTIONS (#2288)
Browse files Browse the repository at this point in the history
Closes #2253
  • Loading branch information
Ralph authored and abernix committed Feb 19, 2019
1 parent 0f9da0c commit 2f77362
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### vNEXT

- `apollo-server-koa`: Support OPTIONS requests [PR #2288](https://github.com/apollographql/apollo-server/pull/2288)

### v2.4.2

- `apollo-server-fastify` is now on Apollo Server and lives within the `apollo-server` repository. This is being introduced in a _patch_ version, however it's a _major_ version bump from the last time `apollo-server-fastify` was published under `1.0.2`. [PR #1971](https://github.com/apollostack/apollo-server/pull/1971)
Expand Down
7 changes: 7 additions & 0 deletions packages/apollo-server-koa/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ export class ApolloServer extends ApolloServerBase {

app.use(
middlewareFromPath(path, (ctx: Koa.Context, next: Function) => {
if (ctx.request.method === 'OPTIONS') {
ctx.status = 204;
ctx.body = '';
return;
}

if (this.playgroundOptions && ctx.request.method === 'GET') {
// perform more expensive content-type check only if necessary
const accept = accepts(ctx.req);
Expand All @@ -187,6 +193,7 @@ export class ApolloServer extends ApolloServerBase {
return;
}
}

return graphqlKoa(() => {
return this.createGraphQLServerOptions(ctx);
})(ctx, next);
Expand Down

0 comments on commit 2f77362

Please sign in to comment.