diff --git a/index.js b/index.js index 184210b..53f5aae 100644 --- a/index.js +++ b/index.js @@ -4,12 +4,23 @@ const cors = require("cors"); const app = express(); const corsOptions = { - origin: "http://localhost:3000/", + origin: "*", credentials: true, optionSucessStatus: 200, + origin: true, }; app.use(cors(corsOptions)); +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(); +}); + app.get("/api/get/*", async (req, res) => { const urlLink = req.params[0]; const authHeaders = req.headers.authorization || null; @@ -50,6 +61,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, diff --git a/vercel.json b/vercel.json index d2d8576..4b09651 100644 --- a/vercel.json +++ b/vercel.json @@ -6,10 +6,31 @@ "use": "@now/node" } ], - "routes": [ + "rewrites": [ { - "src": "/(.*)", - "dest": "index.js" + "source": "/(.*)", + "destination": "index.js" + } + ], + "headers": [ + { + "source": "/api/post/(.*)", + + "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" + } + ] } ] }