From 3fa133d4ec2a9c4409b4419734f0d421f183a733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Wed, 29 Sep 2021 12:55:08 +0200 Subject: [PATCH] API-27: Enabling CORS --- app.ts | 5 +++++ package-lock.json | 22 ++++++++++++++++++++++ package.json | 1 + 3 files changed, 28 insertions(+) diff --git a/app.ts b/app.ts index a5bdc18..c2acceb 100644 --- a/app.ts +++ b/app.ts @@ -8,6 +8,8 @@ import {dhbwServiceRouter} from './src/models/dhbw-service/DHBWService.router'; import logger from './src/middleware/logger'; import {dhbwRaPlaChangesRouter} from './src/models/dhbw-rapla-changes/DHBWRaPlaChanges.router'; +let cors = require('cors'); + dotenv.config(); if (!process.env.PORT) { @@ -23,6 +25,9 @@ const server: http.Server = http.createServer(app); // here we are adding middleware to parse all incoming requests as JSON app.use(express.json()); +// Use CORS +app.use(cors()); + // Add routers app.use('/dhbw-service', dhbwServiceRouter); app.use('/twitch-highlight-marker', highlightMarkerRouter); diff --git a/package-lock.json b/package-lock.json index da06c1f..7e0a191 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "app-root-path": "^3.0.0", "bcrypt": "^5.0.1", + "cors": "^2.8.5", "debug": "^4.3.1", "dotenv": "^8.2.0", "express": "^4.17.1", @@ -509,6 +510,18 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/debug": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", @@ -2202,6 +2215,15 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "debug": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", diff --git a/package.json b/package.json index 2c119de..80ec8e7 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "dependencies": { "app-root-path": "^3.0.0", "bcrypt": "^5.0.1", + "cors": "^2.8.5", "debug": "^4.3.1", "dotenv": "^8.2.0", "express": "^4.17.1",