api.js 1.19 KB
var express = require('express');
const axios = require('axios');
const convert = require('xml-js');
var router = express.Router();
let xmlParser = require('xml2json');
var searchPubTransPath = require('../setPath');
const moment = require('moment');

/* GET home page. */
router.get('/', function (req, res, next) {
    return res.json({title: 'Express'});
});

router.post('/setOptRoute', async (req, res, next) => {
    var {startLocation, endLocation, endTime, personalVelocity} = req.body;
    try {
        const startLocationX = startLocation.longitude;
        const startLocationY = startLocation.latitude;
        const endLocationX = endLocation.longitude;
        const endLocationY = endLocation.latitude;
        var avgSpeed = personalVelocity;
        if(!avgSpeed){
            avgSpeed = 60;
        }
        console.log('endTime 은? ', endTime, personalVelocity);
        const path = await searchPubTransPath(startLocationX, startLocationY, endLocationX, endLocationY, avgSpeed, endTime);
        const optRoute = path;
        console.log(path);
        return res.json({optRoute: optRoute});
    } catch (e) {
        console.error(e);
        // next(e);
    }
});

module.exports = router;