From a19fdf2d8cf7351e91c4abddfbaa149d003772b7 Mon Sep 17 00:00:00 2001
From: Johanes <antoniusjohanes99@gmail.com>
Date: Thu, 21 Nov 2019 10:55:52 +0700
Subject: [PATCH] fix cors access

---
 index.js          |  7 +++----
 package-lock.json | 14 ++++++++++++++
 package.json      |  1 +
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/index.js b/index.js
index cb0fab8..eb1664e 100644
--- a/index.js
+++ b/index.js
@@ -7,12 +7,11 @@ const getTransaction = require('./getTransaction.js');
 const getSeats = require('./getSeats.js')
 const app = express();
 const { port } = require("./config");
+const cors = require("cors");
 
 
-app.use((req, res, next) => {
-    res.header('Access-Control-Allow-Origin', '*');
-    next();
-});
+
+app.use(cors());
 app.use(bodyParser.urlencoded({ extended: false }));
 app.use(bodyParser.json());
 
diff --git a/package-lock.json b/package-lock.json
index e0ddf29..76d7c23 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -231,6 +231,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"
+      }
+    },
     "cross-spawn": {
       "version": "6.0.5",
       "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz",
@@ -900,6 +909,11 @@
       "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==",
       "dev": true
     },
+    "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/package.json b/package.json
index e9dfcfe..b57825d 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
   "license": "ISC",
   "dependencies": {
     "body-parser": "^1.19.0",
+    "cors": "^2.8.5",
     "dotenv": "^8.2.0",
     "express": "^4.17.1",
     "moment": "^2.24.0",
-- 
GitLab