-
Notifications
You must be signed in to change notification settings - Fork 0
/
cors.js
27 lines (24 loc) · 808 Bytes
/
cors.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
const express = require('express');
const cors = require('cors');
const app = express();
const whitelist = ['http://localhost:3001','http://localhost:3000','http://192.168.0.102:3001','https://serene-mclean-d7b035.netlify.app','https://turtle-chat.netlify.app',
'http://192.168.0.101:19000'];
var corsOptionsDelegate = (req, callback) => {
var corsOptions;
// console.log(req.header('Origin'));
if(whitelist.indexOf(req.header('Origin')) !== -1) {
corsOptions = {
origin: true,
allowHeaders : 'Content-Type,Authorization',
credentials : true
};
}
else {
corsOptions = {
origin: false
};
}
callback(null, corsOptions);
};
exports.cors = cors();
exports.corsWithOptions = cors(corsOptionsDelegate);