From d8167ab1162a5ae4343151d0d11c6010d4e4a787 Mon Sep 17 00:00:00 2001 From: somramnani Date: Tue, 11 Apr 2023 15:46:18 -0400 Subject: [PATCH 01/12] edit cors routes --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 184210b..91f8e7f 100644 --- a/index.js +++ b/index.js @@ -4,12 +4,17 @@ const cors = require("cors"); const app = express(); const corsOptions = { - origin: "http://localhost:3000/", + origin: "*", credentials: true, optionSucessStatus: 200, }; app.use(cors(corsOptions)); +app.use(function (req, res, next) { + res.header("Access-Control-Allow-Origin", "*"); + next(); +}); + app.get("/api/get/*", async (req, res) => { const urlLink = req.params[0]; const authHeaders = req.headers.authorization || null; From a1e7efd1b6f944d1ad08de9910afc8e2419d0c08 Mon Sep 17 00:00:00 2001 From: somramnani Date: Tue, 11 Apr 2023 15:53:19 -0400 Subject: [PATCH 02/12] add headers --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 91f8e7f..948ddbf 100644 --- a/index.js +++ b/index.js @@ -55,6 +55,8 @@ app.get("/api/post/*/:data", async (req, res) => { accept: "application/json", Authorization: authHeaders, "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS", + "Access-Control-Allow-Credentials": true, }, method: "post", url: urlLink, From 26673729fb3f15afd1320992aa79a40a0b68232e Mon Sep 17 00:00:00 2001 From: somramnani Date: Tue, 11 Apr 2023 15:55:30 -0400 Subject: [PATCH 03/12] add headers --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 948ddbf..6114c2f 100644 --- a/index.js +++ b/index.js @@ -10,8 +10,13 @@ const corsOptions = { }; app.use(cors(corsOptions)); -app.use(function (req, res, next) { - res.header("Access-Control-Allow-Origin", "*"); +app.use((req, res, next) => { + res.header("Access-Control-Allow-Origin", req.headers.origin); + res.header("Access-Control-Allow-Credentials", true); + res.header( + "Access-Control-Allow-Headers", + "Origin, X-Requested-With, Content-Type, Accept" + ); next(); }); From d5c55bf736962d8c2c0331fa4552ae178e27c945 Mon Sep 17 00:00:00 2001 From: somramnani Date: Tue, 11 Apr 2023 16:34:35 -0400 Subject: [PATCH 04/12] remove vercel.json --- vercel.json | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 vercel.json diff --git a/vercel.json b/vercel.json deleted file mode 100644 index d2d8576..0000000 --- a/vercel.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "version": 2, - "builds": [ - { - "src": "index.js", - "use": "@now/node" - } - ], - "routes": [ - { - "src": "/(.*)", - "dest": "index.js" - } - ] -} From 85b07bc2c38ba0aa50e5758c5378b76c32974b2d Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 11:34:27 -0400 Subject: [PATCH 05/12] add vercel.json back --- vercel.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 vercel.json diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..d2d8576 --- /dev/null +++ b/vercel.json @@ -0,0 +1,15 @@ +{ + "version": 2, + "builds": [ + { + "src": "index.js", + "use": "@now/node" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "index.js" + } + ] +} From 634c20c4fd01db89a8cf41d03185483322324140 Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 11:39:28 -0400 Subject: [PATCH 06/12] add origin: true --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 6114c2f..53f5aae 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ const corsOptions = { origin: "*", credentials: true, optionSucessStatus: 200, + origin: true, }; app.use(cors(corsOptions)); From 863f2a03dc85df473c293ef5a10eed77d2ea85de Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 11:50:01 -0400 Subject: [PATCH 07/12] add headers --- vercel.json | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index d2d8576..2dd5c2b 100644 --- a/vercel.json +++ b/vercel.json @@ -9,7 +9,22 @@ "routes": [ { "src": "/(.*)", - "dest": "index.js" + "dest": "index.js", + "headers": [ + { "key": "Access-Control-Allow-Credentials", "value": "true" }, + + { "key": "Access-Control-Allow-Origin", "value": "*" }, + + { + "key": "Access-Control-Allow-Methods", + "value": "GET,OPTIONS,PATCH,DELETE,POST,PUT" + }, + + { + "key": "Access-Control-Allow-Headers", + "value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" + } + ] } ] } From 1d04c2b7e575edc20c14b21da5157f89bc365e61 Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 11:55:09 -0400 Subject: [PATCH 08/12] add headers --- vercel.json | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vercel.json b/vercel.json index 2dd5c2b..ad89fdb 100644 --- a/vercel.json +++ b/vercel.json @@ -6,10 +6,16 @@ "use": "@now/node" } ], - "routes": [ + "rewrites": [ { - "src": "/(.*)", - "dest": "index.js", + "source": "/(.*)", + "dest": "index.js" + } + ], + "headers": [ + { + "source": "/(.*)", + "headers": [ { "key": "Access-Control-Allow-Credentials", "value": "true" }, From 8620f804c8a7d30a22bff57e0aae2f2055dda764 Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 11:57:30 -0400 Subject: [PATCH 09/12] add destination to rewrites --- vercel.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index ad89fdb..2288e78 100644 --- a/vercel.json +++ b/vercel.json @@ -9,7 +9,7 @@ "rewrites": [ { "source": "/(.*)", - "dest": "index.js" + "destination": "index.js" } ], "headers": [ From a2061258334c1c6d66fd7b84fd91cbff496e5c55 Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 11:59:41 -0400 Subject: [PATCH 10/12] change header route --- vercel.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index 2288e78..dbf5998 100644 --- a/vercel.json +++ b/vercel.json @@ -14,7 +14,7 @@ ], "headers": [ { - "source": "/(.*)", + "source": "/api/(.*)", "headers": [ { "key": "Access-Control-Allow-Credentials", "value": "true" }, From f0f3a08a1bca495041dfa5c167482d222846adaa Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 12:02:18 -0400 Subject: [PATCH 11/12] change header route --- vercel.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index dbf5998..0458efe 100644 --- a/vercel.json +++ b/vercel.json @@ -14,7 +14,7 @@ ], "headers": [ { - "source": "/api/(.*)", + "source": "/api/post(.*)", "headers": [ { "key": "Access-Control-Allow-Credentials", "value": "true" }, From 5af713cc4b625445289f2b4ae3844d5109905d61 Mon Sep 17 00:00:00 2001 From: somramnani Date: Wed, 12 Apr 2023 12:04:17 -0400 Subject: [PATCH 12/12] change header route --- vercel.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vercel.json b/vercel.json index 0458efe..4b09651 100644 --- a/vercel.json +++ b/vercel.json @@ -14,7 +14,7 @@ ], "headers": [ { - "source": "/api/post(.*)", + "source": "/api/post/(.*)", "headers": [ { "key": "Access-Control-Allow-Credentials", "value": "true" },