-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace cors module with a minimal working handler
micro-cors passes the preflight response to the server handler which fails the request. There's a PR for this that hasn't been merged/released.
- Loading branch information
Showing
3 changed files
with
9 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
import { ApolloServer } from 'apollo-server-micro' | ||
import cors from 'micro-cors' | ||
import { schema } from './graphql' | ||
|
||
const withCors: any = (handler: any) => (req: any, res: any, ...args: any) => { | ||
if (req.method === 'OPTIONS') | ||
res.end() | ||
else { | ||
return handler(req, res, ...args) | ||
} | ||
} | ||
|
||
export const server = new ApolloServer({ | ||
schema, | ||
introspection: true, | ||
playground: true | ||
}) | ||
|
||
export default cors()(server.createHandler()) | ||
export default withCors((server.createHandler())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters