Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 24 additions & 3 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
]
}