From 689a8a7ea663fd6bf5047a520228a511d0908df6 Mon Sep 17 00:00:00 2001 From: NemesisX1 Date: Wed, 18 Oct 2023 00:03:42 +0100 Subject: [PATCH] (fix) cors --- package-lock.json | 68 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +++ src/app.ts | 5 +++- 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 9e58cba..51ccd59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,10 +10,12 @@ "dependencies": { "@types/jest": "^29.5.5", "cookie-parser": "~1.4.4", + "cors": "^2.8.5", "debug": "~2.6.9", "dotenv": "^16.0.0", "express": "~4.16.1", "express-validator": "^7.0.1", + "helmet": "^7.0.0", "html-to-text": "^9.0.5", "http-errors": "~1.6.3", "http-status-codes": "^2.3.0", @@ -31,6 +33,7 @@ "@jest/globals": "^29.7.0", "@tsconfig/node16": "^1.0.0", "@types/cookie-parser": "^1.4.2", + "@types/cors": "^2.8.14", "@types/debug": "^4.1.7", "@types/express": "^4.17.13", "@types/http-errors": "^1.8.1", @@ -1505,6 +1508,15 @@ "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "dev": true }, + "node_modules/@types/cors": { + "version": "2.8.14", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.14.tgz", + "integrity": "sha512-RXHUvNWYICtbP6s18PnOCaqToK8y14DnLd75c6HfyKf228dxy7pHNOQkxPtvXKp/hINFMDjbYzsj63nnpPMSRQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/debug": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.9.tgz", @@ -2565,6 +2577,18 @@ "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", "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": "8.3.6", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", @@ -3621,6 +3645,14 @@ "he": "bin/he" } }, + "node_modules/helmet": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-7.0.0.tgz", + "integrity": "sha512-MsIgYmdBh460ZZ8cJC81q4XJknjG567wzEmv46WOBblDb6TUd3z8/GhgmsM9pn8g2B80tAJ4m5/d3Bi1KrSUBQ==", + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/hexoid": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", @@ -6206,6 +6238,14 @@ "url": "https://github.com/fb55/nth-check?sponsor=1" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.0.tgz", @@ -9257,6 +9297,15 @@ "integrity": "sha512-t73xJJrvdTjXrn4jLS9VSGRbz0nUY3cl2DMGDU48lKl+HR9dbbjW2A9r3g40VA++mQpy6uuHg33gy7du2BKpog==", "dev": true }, + "@types/cors": { + "version": "2.8.14", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.14.tgz", + "integrity": "sha512-RXHUvNWYICtbP6s18PnOCaqToK8y14DnLd75c6HfyKf228dxy7pHNOQkxPtvXKp/hINFMDjbYzsj63nnpPMSRQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/debug": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.9.tgz", @@ -10068,6 +10117,15 @@ "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", "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": "8.3.6", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", @@ -10832,6 +10890,11 @@ "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" }, + "helmet": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-7.0.0.tgz", + "integrity": "sha512-MsIgYmdBh460ZZ8cJC81q4XJknjG567wzEmv46WOBblDb6TUd3z8/GhgmsM9pn8g2B80tAJ4m5/d3Bi1KrSUBQ==" + }, "hexoid": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", @@ -12733,6 +12796,11 @@ "boolbase": "^1.0.0" } }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" + }, "object-inspect": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.0.tgz", diff --git a/package.json b/package.json index 730ab32..e5444e4 100644 --- a/package.json +++ b/package.json @@ -14,10 +14,12 @@ "dependencies": { "@types/jest": "^29.5.5", "cookie-parser": "~1.4.4", + "cors": "^2.8.5", "debug": "~2.6.9", "dotenv": "^16.0.0", "express": "~4.16.1", "express-validator": "^7.0.1", + "helmet": "^7.0.0", "html-to-text": "^9.0.5", "http-errors": "~1.6.3", "http-status-codes": "^2.3.0", @@ -35,6 +37,7 @@ "@jest/globals": "^29.7.0", "@tsconfig/node16": "^1.0.0", "@types/cookie-parser": "^1.4.2", + "@types/cors": "^2.8.14", "@types/debug": "^4.1.7", "@types/express": "^4.17.13", "@types/http-errors": "^1.8.1", diff --git a/src/app.ts b/src/app.ts index 54b4311..0e6dcc5 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,7 +5,8 @@ import express, { RequestHandler, ErrorRequestHandler } from 'express'; import path from 'path'; import cookieParser from 'cookie-parser'; import logger from 'morgan'; - +import cors from "cors"; +import helmet from 'helmet'; import indexRouter from './routes/index'; import theatersRouter from './routes/theaters'; @@ -25,6 +26,8 @@ class App { this.app.set('view engine', 'jade'); this.app.use(logger('dev')); + this.app.use(cors()); + this.app.use(helmet()); this.app.use(express.json()); this.app.use(express.urlencoded({ extended: false })); this.app.use(cookieParser());