main.js 1.75 KB
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);
    });
}