Joung Jiwon

Merge branch 'cal' into 'master'

ejs page



See merge request !12
1 +const express = require('express');
2 +const request = require('request');
3 +const http = require('http');
4 +const app = express();
5 +var bodyParser = require("body-parser");
6 +let path = require('path');
7 +let server = http.createServer(app);
8 +
9 +app.set('view engine','ejs');
10 +app.set('views', path.join(__dirname, 'views'));
11 +app.use(bodyParser.urlencoded({ extended : false }));
12 +
13 +request.post("/", function(req, res){
14 + //let sxv = req.render(sx)
15 + //let syv = req.render(sy)
16 + //let exv = req.render(ex)
17 + //let eyv = req.render(ey)
18 +});
19 +
20 +app.get('/', function (req, response) {
21 + let requestUrl = "https://api.odsay.com/v1/api/searchPubTransPath?SX=127.13973017022232&SY=37.47331630562443&EX=127.08011485487083&EY=37.24312944010195&apiKey=D5/cqOgLNnn/iHrOs3rXewYFNPO6KVQvntHKQ/5muGA"
22 +
23 + request.get(requestUrl, (err, res, body) => {
24 + if (err) {
25 + console.log(`err => ${err}`)
26 + }
27 + else {
28 + if (res.statusCode == 200) {
29 + var result = body
30 + var obj = JSON.parse(result);
31 + //console.log(`body data => ${result}`)
32 + //console.log('ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ')
33 + var time = (obj)["result"]["path"][0].info.totalTime
34 + var pay = (obj)["result"]["path"][0].info.payment
35 + var distance = (obj)["result"]["path"][0].info.totalDistance
36 + response.render('index', {
37 + time: time,
38 + pay: pay,
39 + distance: distance
40 + });
41 + }
42 + }
43 + })
44 +});
45 +
46 +server.listen('3000', 'localhost', function () {
47 + console.log('server listen on port:' + server.address().port);
48 +})
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.