main.js
1.75 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
var url = require('url');
var request = require('request');
module.exports = function(app)
{
app.get('/', function (req, res) {
res.render('Index.html');
});
app.get('/timetable', function (req, res){ // bus list의 특정 버스를 클릭하면, server에 요청
var _url = req.url;
var queryData = url.parse(_url, true).query;
var busNum = queryData.busNum;
request.post(
{
url: 'http://34.206.171.225:23023/reqBusInfo',
body: {
'busNum': busNum,
'testVariable': 'test'
},
json: true
}
);
res.end('http://localhost:23023/resfromControllServer'); // 밑의 get활성화를 위함
});
app.get('/resfromControllServer', function (req, res){
var body = '';
req.on('data', function(data){
body = body + data;
});
req.on('end', function()
{
var post = qs.parse(body);
console.log(body);
});
var resFromServer = body.value1;
var templateTimeTable =
`
<!doctype html>
<html>
<head>
<title>Time Table</title>
<meta charset="utf-8">
<style type="text/css">
a { text-decoration:none }
</style>
</head>
<body>
<h1><a href="/"><p style="text-align:center;">BTT</p></a></h1>
<br>
<h2>${busNum} BUS Time Table</h2>
<br>
${resFromServer}
</body>
</html>
`;
res.send(templateTimeTable);
});
}