diff --git a/package-lock.json b/package-lock.json index d382af8..6a0a013 100644 --- a/package-lock.json +++ b/package-lock.json @@ -92,6 +92,14 @@ "tslib": "~2.1.0" } }, + "@koa/cors": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@koa/cors/-/cors-3.1.0.tgz", + "integrity": "sha512-7ulRC1da/rBa6kj6P4g2aJfnET3z8Uf3SWu60cjbtxTA5g8lxRdX/Bd2P92EagGwwAhANeNw8T8if99rJliR6Q==", + "requires": { + "vary": "^1.1.2" + } + }, "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -243,6 +251,15 @@ "@types/koa": "*" } }, + "@types/koa__cors": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@types/koa__cors/-/koa__cors-3.0.2.tgz", + "integrity": "sha512-gBetQR0DJ9JTG1YQoW33BADHCrDPJGiJUKUUcEPJwW1A2unzpIMhorEpXB6eMaaXTaqHLemcGnq3RmH9XaryRQ==", + "dev": true, + "requires": { + "@types/koa": "*" + } + }, "@types/linkify-it": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.0.tgz", diff --git a/package.json b/package.json index 3d83823..fdc8520 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dependencies": { "@graphql-tools/merge": "^6.2.9", "@graphql-tools/schema": "^6.2.4", + "@koa/cors": "^3.1.0", "dotenv": "^8.2.0", "graphql": "^15.5.0", "graphql-tag": "^2.11.0", @@ -21,6 +22,7 @@ "@types/koa": "^2.13.0", "@types/koa-bodyparser": "^4.3.0", "@types/koa-router": "^7.4.1", + "@types/koa__cors": "^3.0.2", "@types/markdown-it": "^10.0.3", "@types/physical-cpu-count": "^2.0.0", "@types/stoppable": "^1.1.0", diff --git a/src/main.ts b/src/main.ts index e157910..5dc18e6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,12 +3,17 @@ import { applyGraphQL } from "./graphql"; import { typeDefs, resolvers } from "./graphql/index"; import stoppable from "stoppable"; +import cors from "@koa/cors"; + const runtime: { server: undefined | stoppable.StoppableServer } = { server: undefined, }; async function main() { const app = new Application(); + + app.use(cors()); + app.use( bodyParser({ enableTypes: ["json"],