-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.js
More file actions
67 lines (57 loc) · 2.1 KB
/
dump.js
File metadata and controls
67 lines (57 loc) · 2.1 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var express = require('express');
var fs = require('fs');
var path = require('path');
var appDir = path.dirname(require.main.filename) + '/';
const { createProxyMiddleware } = require('http-proxy-middleware');
var app = express();
const apconf = "https://d2cgv6cqxnj0mc.cloudfront.net";
const backend = "https://prds.lid.gungho.jp";
const cache = "https://d1lys6imrj0r6g.cloudfront.net"
const dumpDir = "dump"
logRequest = (proxyReq, req, res) => {
var reqData = [];
req.on('data', function(chunk){ reqData.push(chunk)})
req.on('end', function(){
fs.mkdir(appDir + dumpDir + req.path + '/' + req.method, { recursive: true }, (err) => {
if (err) throw err;
fs.writeFileSync(appDir + dumpDir + req.path + '/' + req.method + '/req_' + Date.now(), Buffer.concat(reqData));
});
console.log(Buffer.concat(reqData));
});
console.log(proxyReq.headers);
var body = [];
proxyReq.on('data', function(data) {
body.push(data);
});
proxyReq.on('end', () => {
fs.mkdir(appDir + dumpDir + req.path + '/' + req.method, { recursive: true }, (err) => {
if (err) throw err;
fs.writeFileSync(appDir + dumpDir + req.path + '/' + req.method + '/res_' + Date.now(), Buffer.concat(body));
});
});
}
app.all("*", (req, resp, next) => {
console.log(req.method + ' ' + req.hostname + ' ' + req.path);
next();
});
app.use('/ap.conf', createProxyMiddleware({ target: apconf, changeOrigin: true,
onProxyRes: logRequest,
onProxyReq: logRequest
}));
app.use('/api/getparams.php', (req, resp) => {
resp.send(fs.readFileSync(appDir + dumpDir + '/api/getparams.php' + req.path + '/' + req.method + '/' + 'apiparams.json'));
});
app.use('/api/getlocdat.php', (req, resp) => {
resp.send(fs.readFileSync(appDir + dumpDir + '/api/getlocdat.php' + req.path + '/' + req.method + '/' + 'locdat.json'));
});
app.use('/api', createProxyMiddleware({ target: backend, changeOrigin: true,
onProxyRes: logRequest,
onProxyReq: logRequest
}));
app.use('/cache', createProxyMiddleware({ target: cache, changeOrigin: true,
onProxyRes: logRequest,
onProxyReq: logRequest
}));
app.listen(1337, () => {
console.log('listening on port 1337');
});