From 478b4b688d3834c6a347cfff6d6adf42067740ca Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Mon, 9 Nov 2020 14:20:43 +0100 Subject: [PATCH] index.ts: cors --- package.json | 1 + src/index.ts | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f214c48..6db1674 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ }, "dependencies": { "apollo-server-express": "^2.17.0", + "cors": "^2.8.5", "crc": "^3.8.0", "dotenv": "^8.2.0", "express": "^4.17.1", diff --git a/src/index.ts b/src/index.ts index 99eafdd..2ac3d02 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,7 +36,7 @@ import workshopResolvers from './resolvers/workshopResolvers'; import { ActionLog } from './model/ActionLog'; import actionLogResolvers from './resolvers/actionLogResolvers'; import { ActionLogAPI } from './datasources/db/actionLogAPI'; -const cors = require('express-cors'); +const cors = require('cors'); require('dotenv').config(); const connOptions: ConnectionOptions = { @@ -131,15 +131,11 @@ const server = new ApolloServer({ }); const app = express(); - +app.use(cors()); app.post('/graphql', authenticate); app.get(/\/graphql?&.*query=/, authenticate); + server.applyMiddleware({ app }); -app.use(cors({ - allowedOrigins: [ - '*' - ] -})); app.listen(4000, async () => { await userAPI.createDefinedPermissions().catch( err => console.log(err));