forked from maxlorenz/rt-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (29 loc) · 1.08 KB
/
index.js
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
'use strict';
// routing
let loader = require('./lib/loader');
let searcher = require('./tools/searcher');
let astar = require('./algorithms/a-star');
let dijkstra = require('./algorithms/dijkstra');
// server
let app = require('express')();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
loader.afterLoading('./example/monaco.osm.pbf', cache => {
var routeAstar = astar.astar(cache);
var routeDijkstra = dijkstra.dijkstra(cache);
var search = searcher.searcher(cache);
app.get('/astar/from/:fromId/to/:toId', (req, res) => {
routeAstar(req.params.fromId, req.params.toId, path => res.json(path));
});
app.get('/dijkstra/from/:fromId/to/:toId', (req, res) => {
routeDijkstra(req.params.fromId, req.params.toId, path => res.json(path));
});
app.get('/search/:keyword', (req, res) => {
search(req.params.keyword, results => res.json(results));
});
});
console.log('Listening on localhost:6833');
console.log('Try http://localhost:6833/astar/from/25199246/to/25200449');
app.listen(6833);