-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
28 lines (24 loc) · 909 Bytes
/
index.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
"use strict";
var fetch = require('./lib/fetchParams.js')
, imsi = require('./lib/mncMcc.js')
, checkErr = require('./lib/checkInvalidReq.js')
, geoInfo = require('./lib/geoInfo.js');
/**
*
* @param option : this has key list of fetch parameter
* @param addOn : this has add on key list
* - geoip : config info describes how to fetch geo information from http request
* - imsi : get full mcc, mnc, country code info by mnc code or mcc code
* @returns {Function}
*/
module.exports = function(option, addOn) {
return function(req, res, next) {
req.fetchParameter = fetch.fetchParameter.bind({req: req, extraOption: option});
req.checkParamErr = checkErr.checkParamErr;
if (addOn) {
if (addOn.geoip) req.headers['x-fetcher-geoinfo'] = geoInfo.fetch(req, addOn.geoip);
if (addOn.imsi) imsi.addImsi(req);
}
return next();
};
};