forked from vbhjckfd/timetable-api-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.54 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
41
42
43
44
45
46
const mongoose = require('mongoose');
const dotenv = require('dotenv');
dotenv.config();
const cors = require('cors')
const express = require('express');
const dbConfig = {
user: process.env.MONGO_IMPORT_USER,
pass: process.env.MONGO_IMPORT_PASSWORD,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
}
mongoose.connect(process.env.MONGO_GTFS_URL, dbConfig);
const notFoundAction = require('./actions/notFoundAction');
const getClosestStopsAction = require('./actions/getClosestStopsAction');
const getSingleStopAction = require('./actions/getSingleStopAction');
const importGtfsStaticAction = require('./actions/importGtfsStaticAction');
const routeInfoDynamicAction = require('./actions/routeDynamicInfoAction');
const routeInfoStaticAction = require('./actions/routeStaticInfoAction');
const vehicleInfoAction = require('./actions/vehicleInfoAction');
const closestTransportAction = require('./actions/closestTransportAction');
const app = express();
app.use(cors());
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).send('Something broke!');
});
app.get('/stops/:code', getSingleStopAction);
app.get('/closest', getClosestStopsAction);
app.get('/import/gtfs_static', importGtfsStaticAction);
app.get('/routes/dynamic/:name', routeInfoDynamicAction);
app.get('/routes/static/:name', routeInfoStaticAction);
app.get('/vehicle/:vehicleId', vehicleInfoAction);
app.get('/transport', closestTransportAction);
app.use(notFoundAction);
process.on('exit', mongoose.disconnect);
exports.timetable = app;