-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
39 lines (35 loc) · 1.05 KB
/
utils.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
let users = [
{
id: 1,
username: process.env.DB_USER,
password: process.env.DB_PASS
}
];
// seconds
const durationRefreshToken = 129600; // 90 d
const durationToken = 900; // 15 min
function centralErrorHandler(err, req, res, next) {
if (err.name === 'UnauthorizedError') {
res.status(401).send(err);
} else if (err.message == 'Not allowed by CORS') {
res.status(401).send('Not allowed from this origin.');
} else {
next(err);
}
}
var whitelist = ['https://gutschein2go.at'];
var corsOptions = {
origin: function (origin, callback) {
console.log('Request from origin: ' + origin);
if (whitelist.indexOf(origin) !== -1) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
}
}
module.exports.centralErrorHandler = centralErrorHandler;
module.exports.users = users;
module.exports.durationRefreshToken = durationRefreshToken;
module.exports.durationToken = durationToken;
module.exports.corsOptions = corsOptions;