From 45001d16fece9dbad0d6a4823d202ca1e7a79bd3 Mon Sep 17 00:00:00 2001 From: Elias Date: Fri, 27 Mar 2020 13:30:47 +0100 Subject: [PATCH] Add cors support to the api --- server/package-lock.json | 23 +++++++++++++++++++++++ server/package.json | 2 ++ server/src/apps/api/index.ts | 2 ++ 3 files changed, 27 insertions(+) diff --git a/server/package-lock.json b/server/package-lock.json index 1454161..824b802 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -65,6 +65,15 @@ "@types/node": "*" } }, + "@types/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-invOmosX0DqbpA+cE2yoHGUlF/blyf7nB0OGYBBiH27crcVm5NmFaZkLP4Ta1hGaesckCi5lVLlydNJCxkTOSg==", + "dev": true, + "requires": { + "@types/express": "*" + } + }, "@types/express": { "version": "4.17.3", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.3.tgz", @@ -591,6 +600,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" + } + }, "create-error-class": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/create-error-class/-/create-error-class-3.0.2.tgz", @@ -1467,6 +1485,11 @@ "path-key": "^2.0.0" } }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", diff --git a/server/package.json b/server/package.json index deb70aa..fc3bc49 100644 --- a/server/package.json +++ b/server/package.json @@ -14,6 +14,7 @@ "license": "ISC", "dependencies": { "axios": "^0.19.2", + "cors": "^2.8.5", "express": "^4.17.1", "express-pino-logger": "^4.0.0", "mongoose": "^5.9.5", @@ -24,6 +25,7 @@ "yup": "^0.28.3" }, "devDependencies": { + "@types/cors": "^2.8.6", "@types/express": "^4.17.3", "@types/express-pino-logger": "^4.0.2", "@types/mongoose": "^5.7.6", diff --git a/server/src/apps/api/index.ts b/server/src/apps/api/index.ts index 3e8d101..00b8f27 100644 --- a/server/src/apps/api/index.ts +++ b/server/src/apps/api/index.ts @@ -1,5 +1,6 @@ import * as express from "express"; import * as expressPino from "express-pino-logger"; +import * as cors from "cors"; import { config } from "../../shared/infrastructure/config/config"; import { logger } from "../../shared/infrastructure/logging"; @@ -15,6 +16,7 @@ function bootstrap(): void { const app: express.Express = express(); app.use(expressPino({ logger })); + app.use(cors()); app.use("/autonomous-communities", autonomousCommunitiesRouter); app.use("/reports", reportsRouter);