test.js
1.63 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
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
*
*/
'use strict';
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const list = [
'app.product.refundExchange',
'app.shopsdecorator.getList',
'getCategory',
'h5.product.data',
'h5.product.intro',
'sortgroup',
'web.brand.banner',
'web.brand.byDomain',
'web.productBanner.data',
'web.productComfort.data',
'web.productModelcard.list',
'web.productModelTry.data'
];
let client = (path) => {
return new Promise((resolve, reject) => {
let options = {
hostname: '192.168.102.162',
port: 80,
path: path,
method: 'GET'
};
let req = http.request(options, (res) => {
// console.log(`STATUS: ${res.statusCode}`);
// console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
let ret = '';
res.on('data', (chunk) => {
ret += chunk.toString();
});
res.on('end', () => {
resolve(JSON.parse(ret));
});
});
req.on('error', (e) => {
reject(e);
console.log(`problem with request: ${e.message}`);
});
req.end();
});
};
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
let calls = [];
list.forEach((val,index)=>{
console.log(`/${val}.json`);
let call = client(`/${val}.json`);
calls.push(call);
});
Promise.all(calls).then(function(datas) {
let ret = JSON.stringify(datas);
res.end(ret);
})
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});