-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidapirequest.js
35 lines (28 loc) · 1.01 KB
/
validapirequest.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
const CheckValidApiSource = async(req, res, next) => {
try {
// check for the host of api request
if (!req.headers['user-agent']) {
throw new Error('No user Agent present');
}
// check if app type header not present
if (!req.headers['x-app-type']) {
throw new Error('app type header not present');
}
// check for the method of api request
if (req.headers['x-app-type'] !== 'OffermeRequest') {
throw new Error('Invalid App Type');
}
// check if hashed id header not present
if (!req.headers['x-hashed-id']) {
throw new Error('hashed id not present');
}
// check if request token not present
if (!req.headers['x-request-token']) {
throw new Error('request token not present');
}
}
catch (err) {
res.status(500).send({ message: err.message || 'An error occurred.' });
}
};
module.exports = CheckValidApiSource;