From 54b394f7f4d2a5ea75b5dbf9cab06d0503287c0f Mon Sep 17 00:00:00 2001 From: Olojakpoke Daniel Date: Tue, 16 May 2023 03:01:16 +0100 Subject: [PATCH] fix: cors --- .../overlays/development/kustomization.yaml | 4 +-- deployment/overlays/development/mapping.yaml | 11 ------- package-lock.json | 30 +++++++++++++++---- package.json | 1 + server/app.js | 5 ++++ yarn.lock | 24 +++++++-------- 6 files changed, 42 insertions(+), 33 deletions(-) delete mode 100644 deployment/overlays/development/mapping.yaml diff --git a/deployment/overlays/development/kustomization.yaml b/deployment/overlays/development/kustomization.yaml index 501cae77..6d0735b6 100644 --- a/deployment/overlays/development/kustomization.yaml +++ b/deployment/overlays/development/kustomization.yaml @@ -1,4 +1,2 @@ -patchesStrategicMerge: - - mapping.yaml -resources: +bases: - ../../base diff --git a/deployment/overlays/development/mapping.yaml b/deployment/overlays/development/mapping.yaml deleted file mode 100644 index c1f18ae3..00000000 --- a/deployment/overlays/development/mapping.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: getambassador.io/v2 -kind: Mapping -metadata: - name: treetracker-wallet-api-v2 -spec: - cors: - origins: '*' - methods: GET, POST, PATCH, OPTIONS - headers: - - Content-Type - - Authorization diff --git a/package-lock.json b/package-lock.json index 300b1449..3b9fb06f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "treetracker", - "version": "1.19.7", + "version": "1.19.14", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "treetracker", - "version": "1.19.7", + "version": "1.19.14", "license": "GPL-3.0-or-later", "dependencies": { "@sentry/node": "^5.1.0", "bcryptjs": "^2.4.3", "chai-uuid": "^1.0.6", + "cors": "^2.8.5", "dotenv": "^8.2.0", "expect": "^26.4.2", "expect-runtime": "^0.7.0", @@ -2787,6 +2788,18 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "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/cosmiconfig": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.0.tgz", @@ -7603,7 +7616,6 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -12705,6 +12717,15 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "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" + } + }, "cosmiconfig": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.0.tgz", @@ -16397,8 +16418,7 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "object-copy": { "version": "0.1.0", diff --git a/package.json b/package.json index de98a0df..1d462459 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@sentry/node": "^5.1.0", "bcryptjs": "^2.4.3", "chai-uuid": "^1.0.6", + "cors": "^2.8.5", "dotenv": "^8.2.0", "expect": "^26.4.2", "expect-runtime": "^0.7.0", diff --git a/server/app.js b/server/app.js index 52be8437..92ce6862 100644 --- a/server/app.js +++ b/server/app.js @@ -1,11 +1,16 @@ const express = require('express'); const Sentry = require('@sentry/node'); +const cors = require('cors'); const HttpError = require('./utils/HttpError'); const routes = require('./routes'); const { errorHandler, handlerWrapper } = require('./utils/utils'); const app = express(); +if (process.env.NODE_ENV === 'development') { + app.use(cors()); +} + const config = require('../config/config.js'); Sentry.init({ dsn: config.sentry_dsn }); diff --git a/yarn.lock b/yarn.lock index a7c04141..13aad793 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1405,6 +1405,14 @@ "resolved" "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" "version" "1.0.2" +"cors@^2.8.5": + "integrity" "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==" + "resolved" "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz" + "version" "2.8.5" + dependencies: + "object-assign" "^4" + "vary" "^1" + "cosmiconfig@^5.2.1": "integrity" "sha512-H65gsXo1SKjf8zmrJ67eJk8aIRKV5ff2D4uKZIBZShbhGSpEmsQOPW/SKMKYhSTrqR7ufy6RP69rPogdaPh/kA==" "resolved" "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz" @@ -1426,13 +1434,6 @@ "path-type" "^4.0.0" "yaml" "^1.10.0" -"cpu-features@0.0.2": - "integrity" "sha512-/2yieBqvMcRj8McNzkycjW2v3OIUOibBfd2dLEJ0nWts8NobAxwiyw9phVNS6oDL8x8tz9F7uNVFEVpJncQpeA==" - "resolved" "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.2.tgz" - "version" "0.0.2" - dependencies: - "nan" "^2.14.1" - "cross-spawn@^6.0.0": "integrity" "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==" "resolved" "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz" @@ -3864,11 +3865,6 @@ "resolved" "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz" "version" "0.0.8" -"nan@^2.14.1", "nan@^2.15.0": - "integrity" "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==" - "resolved" "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz" - "version" "2.15.0" - "nanoid@3.3.3": "integrity" "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==" "resolved" "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz" @@ -4022,7 +4018,7 @@ "test-exclude" "^6.0.0" "yargs" "^15.0.2" -"object-assign@^4.1.1": +"object-assign@^4", "object-assign@^4.1.1": "integrity" "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" "resolved" "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz" "version" "4.1.1" @@ -5671,7 +5667,7 @@ "resolved" "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz" "version" "13.7.0" -"vary@~1.1.2": +"vary@^1", "vary@~1.1.2": "integrity" "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" "resolved" "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz" "version" "1.1.2"