1
1
const express = require ( 'express' ) ;
2
2
const cors = require ( 'cors' ) ;
3
3
const bodyParser = require ( "body-parser" ) ;
4
- const { route, closest, distance} = require ( './src/pgRouting' ) ;
4
+ const { route, closest, distance, topology } = require ( './src/pgRouting' ) ;
5
5
const { exp_config } = require ( './src/config' ) ;
6
6
7
- // use nodemon no need to use webpack-hot-middleware and webpackDevMiddleware for express
8
- //
9
- // import webpackDevMiddleware from 'webpack-dev-middleware'
10
- // import config from '../webpack.config'
11
- // import webpackHotMiddleware from 'webpack-hot-middleware'
12
- // import webpack from 'webpack'
13
-
14
7
const app = express ( ) ;
15
- // const compiler = webpack(config);
16
8
app . use ( cors ( ) ) ;
17
9
app . use ( bodyParser . json ( ) ) ;
18
10
19
- // use nodemon no need to use webpack-hot-middleware and webpackDevMiddleware for express
20
- // app.use(webpackDevMiddleware(compiler, {
21
- // publicPath: config.output.publicPath
22
- // }));
23
- // app.use(webpackHotMiddleware(compiler));
24
-
25
- app . get ( '/' , ( req , res ) => {
11
+ app . get ( '/api' , ( req , res ) => {
26
12
res . send ( 'Welcome to PG Routing API Written in Node JS Express!' ) ;
27
13
} ) ;
28
14
29
- app . get ( '/route' , async ( req , res , next ) => {
15
+ app . get ( '/api/ route' , async ( req , res , next ) => {
30
16
31
17
const { start, end } = req . query ;
32
18
route ( start , end )
@@ -38,7 +24,7 @@ app.get('/route', async(req, res, next) => {
38
24
} ) ;
39
25
} ) ;
40
26
41
- app . get ( '/distance' , async ( req , res , next ) => {
27
+ app . get ( '/api/ distance' , async ( req , res , next ) => {
42
28
const { start, end } = req . query ;
43
29
distance ( start , end )
44
30
. then ( ( result ) => {
@@ -49,7 +35,7 @@ app.get('/distance', async(req, res, next) => {
49
35
} ) ;
50
36
} ) ;
51
37
52
- app . get ( '/closest' , async ( req , res , next ) => {
38
+ app . get ( '/api/ closest' , async ( req , res , next ) => {
53
39
const { lat, lng } = req . query ;
54
40
const buffer = values . buffer || 1 ;
55
41
const limit = values . limit || 1 ;
@@ -62,4 +48,14 @@ app.get('/closest', async(req, res, next) => {
62
48
} ) ;
63
49
} ) ;
64
50
51
+ app . get ( '/api/topology' , async ( req , res , next ) => {
52
+ topology ( )
53
+ . then ( ( result ) => {
54
+ res . status ( 200 ) . json ( { result : "Okay" } ) ;
55
+ } )
56
+ . catch ( ( reason ) => {
57
+ res . status ( 500 ) . json ( reason ) ;
58
+ } ) ;
59
+ } ) ;
60
+
65
61
app . listen ( exp_config . port , ( ) => console . log ( `app listening on port ${ exp_config . port } !` ) ) ;
0 commit comments