Skip to content

Commit

Permalink
Now: allow OPTIONS requests
Browse files Browse the repository at this point in the history
  • Loading branch information
juusaw committed Feb 27, 2019
1 parent c69e739 commit fa91a70
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion now.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"src": "/(.*)",
"dest": "src/micro.ts",
"headers": {
"Access-Control-Allow-Origin": "*"
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, Content-Type, Accept"
}
}]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"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 All @@ -18,6 +19,7 @@
"devDependencies": {
"@types/graphql": "^14.0.7",
"@types/jest": "^24.0.5",
"@types/micro-cors": "^0.1.0",
"jest": "^24.1.0",
"ts-jest": "^23.10.5",
"ts-node": "^8.0.2"
Expand Down
3 changes: 2 additions & 1 deletion src/micro.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloServer } from 'apollo-server-micro'
import cors from 'micro-cors'
import { schema } from './graphql'

export const server = new ApolloServer({
Expand All @@ -7,4 +8,4 @@ export const server = new ApolloServer({
playground: true
})

export default server.createHandler()
export default cors()(server.createHandler())
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,20 @@
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.0.tgz#719551d2352d301ac8b81db732acb6bdc28dbdef"

"@types/micro-cors@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@types/micro-cors/-/micro-cors-0.1.0.tgz#4ee6da45a80373230c6c4ceaba80fa05523db2e1"
integrity sha512-82Ug+VjbCLLN/cNbvRmIr49PA15HrRH+VcAUoDIZeMnWGQCJx2vmSYZy/S7DvqrmEoOZquwuxbs5w/8dfMSbcQ==
dependencies:
"@types/micro" "*"

"@types/micro@*":
version "7.3.3"
resolved "https://registry.yarnpkg.com/@types/micro/-/micro-7.3.3.tgz#31ead8df18ac10d58b7be1186d4b2d977b13a938"
integrity sha512-I3n3QYT7lqAxkyAoTZyg1yrvo38BxW/7ZafLAXZF/zZQOnAnQzg6j9XOuSmUEL5GGVFKWw4iqM+ZLnqb2154TA==
dependencies:
"@types/node" "*"

"@types/mime@*":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.1.tgz#dc488842312a7f075149312905b5e3c0b054c79d"
Expand Down Expand Up @@ -2462,6 +2476,11 @@ 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 fa91a70

Please sign in to comment.