-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (42 loc) · 1.08 KB
/
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const app = require('express')();
const bodyParser = require('body-parser');
const multer = require('multer')();
const http = require('http').Server(app);
app.use((req, res, next) => {
const contentType = req.headers['content-type'] || '';
const mime = contentType.split(';')[0];
if (mime === 'multipart/form-data') {
let data = '';
req.setEncoding('utf8');
req.on('data', chunk => {
data += chunk;
});
req.on('end', () => {
req.rawBody = data;
});
}
next();
});
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false,
verify: (req, res, buf, encoding) => {
console.log('next');
if (buf && buf.length) {
req.rawBody = buf.toString(encoding || 'utf8');
}
}
})
);
app.all('*', multer.none(), (req, res) => {
res.status(200).json({
'request-headers': req.headers,
'request-query-data': req.query || {},
'request-body-data': req.body || {},
'request-raw-body': req.rawBody || {}
});
});
http.listen(65432, () => {
console.log('listening on http://localhost:65432');
});