-
Notifications
You must be signed in to change notification settings - Fork 0
/
corsConfig.js
43 lines (39 loc) · 996 Bytes
/
corsConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require('dotenv').config();
const corsOptions = {
origin: (origin, callback) => {
const allowedOrigins = [
process.env.CORS_ORIGIN,
"https://dash.icespyonline.com",
"https://gateway.icespyonline.com"
];
// Allow requests with no origin (like mobile apps or curl requests)
if (!origin) {
return callback(null, true);
}
if (allowedOrigins.includes(origin)) {
callback(null, true);
} else {
console.log("Blocked CORS for origin:", origin);
callback(new Error(`${origin} is not allowed by CORS`));
}
},
methods: ["GET", "PATCH", "DELETE", "POST", "OPTIONS"],
allowedHeaders: [
"Content-Type",
"x-company-id",
"x-company-name",
"x-company-id",
"x-company-name",
"Authorization",
"x-csrf-token",
"X-Requested-With",
"Accept"
],
credentials: true,
preflightContinue: false,
optionsSuccessStatus: 204,
maxAge: 86400 // 24 hours
};
module.exports = {
corsOptions,
};