Commit fded55b393e7ae91abd80b782d697396316219a5
1 parent
e462e6e6c6
Exists in
master
Log all request
Showing 1 changed file with 22 additions and 2 deletions Side-by-side Diff
lib/http-listener.js
... | ... | @@ -35,7 +35,7 @@ const port = (config && config.listener && config.listener.http |
35 | 35 | function mainHandler(req, res) { |
36 | 36 | if (!req.body) req.body = {}; |
37 | 37 | |
38 | - const xid = uniqid(); | |
38 | + const { xid } = res.locals; | |
39 | 39 | |
40 | 40 | logger.verbose(`${MODULE_NAME} 72AFD326: Got a request`, { |
41 | 41 | xid, |
... | ... | @@ -152,8 +152,28 @@ if (config.ip_whitelist && config.ip_whitelist.length) { |
152 | 152 | app.use(ipfilter(config.ip_whitelist, { mode: 'allow', log: false })); |
153 | 153 | } |
154 | 154 | |
155 | +app.use((req, res, next) => { | |
156 | + const xid = uniqid(); | |
157 | + res.locals.xid = xid; | |
158 | + | |
159 | + logger.verbose(`${MODULE_NAME} 83DF8231: Got a request`, { | |
160 | + xid, | |
161 | + ip: req.ip, | |
162 | + method: req.method, | |
163 | + requestContentType: req.get('content-type'), | |
164 | + url: req.url, | |
165 | + }); | |
166 | + | |
167 | + next(); | |
168 | +}); | |
169 | + | |
155 | 170 | app.get('/', mainHandler); |
156 | -app.post('/', express.urlencoded({ extended: true }), mainHandler); | |
171 | +app.post( | |
172 | + '/', | |
173 | + express.urlencoded({ extended: true }), | |
174 | + express.json(), | |
175 | + mainHandler, | |
176 | +); | |
157 | 177 | |
158 | 178 | app.listen(port, () => { |
159 | 179 | logger.info('HTTP-LISTENER: started', { |