-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
45 lines (34 loc) · 1.03 KB
/
logic.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
44
45
const mod = {
OLSKClientKeyHeaderGuard (param1, param2) {
if (typeof param1 !== 'object' || param1 === null) {
throw new Error('RCSErrorInputNotValid');
}
if (typeof param2 !== 'string') {
throw new Error('RCSErrorInputNotValid');
}
if (param1['x-client-key'] !== param2) {
return new Error('OLSKRoutingErrorNotFound');
}
},
OLSKClientKeyHeaderGuardMiddlewareFunction (inputData) {
return function (req, res, next) {
return next(mod.OLSKClientKeyHeaderGuard(req.headers, inputData));
};
},
OLSKAllowAllOriginsMiddleware (req, res, next) {
if (typeof res !== 'object' || res === null) {
throw new Error('OLSKErrorInputNotValid');
}
if (typeof res.header !== 'function') {
throw new Error('OLSKErrorInputNotValid');
}
res.header('Access-Control-Allow-Origin', '*');
return next();
},
OLSKCommonMiddlewares () {
return Object.fromEntries(Object.entries(mod).filter(function (e) {
return e[0].match(/Middleware$/) && !e[0].match(/(_|Error)/);
}));
},
};
Object.assign(exports, mod);