Skip to content

Commit

Permalink
Replace cors module with a minimal working handler
Browse files Browse the repository at this point in the history
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
juusaw committed Feb 28, 2019
1 parent fa91a70 commit b237b3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"apollo-server-micro": "^2.4.0",
"graphql": "^14.1.1",
"micro": "^9.3.3",
"micro-cors": "^0.1.1",
"typescript": "^3.3.3"
},
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions src/micro.ts
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()))
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2476,11 +2476,6 @@ methods@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"

micro-cors@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/micro-cors/-/micro-cors-0.1.1.tgz#af7a480182c114ffd1ada84ad9dffc52bb4f4054"
integrity sha512-6WqIahA5sbQR1Gjexp1VuWGFDKbZZleJb/gy1khNGk18a6iN1FdTcr3Q8twaxkV5H94RjxIBjirYbWCehpMBFw==

micro@^9.3.2, micro@^9.3.3:
version "9.3.3"
resolved "https://registry.yarnpkg.com/micro/-/micro-9.3.3.tgz#32728c7be15e807691ead85da27fd8117a8bca24"
Expand Down

0 comments on commit b237b3f

Please sign in to comment.