2017-10-23 23:13:53 +02:00
|
|
|
|
'use strict'
|
|
|
|
|
|
2018-10-25 21:49:17 +02:00
|
|
|
|
const createHafas = require('db-hafas')
|
2017-12-16 09:06:35 +01:00
|
|
|
|
const createApi = require('hafas-rest-api')
|
2018-11-21 00:00:55 +01:00
|
|
|
|
const createHealthCheck = require('hafas-client-health-check')
|
2017-10-23 23:13:53 +02:00
|
|
|
|
|
2017-12-16 09:06:35 +01:00
|
|
|
|
const pkg = require('./package.json')
|
2020-04-30 15:48:06 +02:00
|
|
|
|
const stations = require('./routes/stations')
|
|
|
|
|
const station = require('./routes/station')
|
2017-10-23 23:13:53 +02:00
|
|
|
|
|
2018-10-25 21:49:17 +02:00
|
|
|
|
const hafas = createHafas(pkg.name)
|
|
|
|
|
|
2018-11-21 00:00:55 +01:00
|
|
|
|
const berlinHbf = '8011160'
|
|
|
|
|
const healthCheck = createHealthCheck(hafas, berlinHbf)
|
2018-10-25 21:49:17 +02:00
|
|
|
|
|
2020-04-30 15:48:06 +02:00
|
|
|
|
const modifyRoutes = (routes) => {
|
|
|
|
|
routes['/stations'] = stations
|
|
|
|
|
routes['/stations/:id'] = station
|
|
|
|
|
return routes
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-16 09:06:35 +01:00
|
|
|
|
const config = {
|
2020-04-26 18:12:57 +02:00
|
|
|
|
hostname: process.env.HOSTNAME || 'localhost',
|
2018-10-25 22:56:45 +02:00
|
|
|
|
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
|
2017-12-16 09:06:35 +01:00
|
|
|
|
name: pkg.name,
|
2018-03-07 02:33:49 +01:00
|
|
|
|
description: pkg.description,
|
2018-01-09 16:42:30 +01:00
|
|
|
|
homepage: pkg.homepage,
|
2018-10-25 21:49:17 +02:00
|
|
|
|
version: pkg.version,
|
2020-05-01 18:51:03 +02:00
|
|
|
|
docsLink: 'https://github.com/derhuerst/db-rest/blob/5/docs/readme.md',
|
2018-03-07 02:33:49 +01:00
|
|
|
|
logging: true,
|
2019-02-04 16:09:30 +01:00
|
|
|
|
aboutPage: true,
|
2020-04-30 15:48:06 +02:00
|
|
|
|
etags: 'strong',
|
|
|
|
|
healthCheck,
|
|
|
|
|
modifyRoutes,
|
2018-10-25 21:49:17 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-30 15:48:06 +02:00
|
|
|
|
const api = createApi(hafas, config, () => {})
|
2017-12-16 09:06:35 +01:00
|
|
|
|
|
|
|
|
|
api.listen(config.port, (err) => {
|
2020-04-30 15:48:06 +02:00
|
|
|
|
const {logger} = api.locals
|
2017-10-23 23:13:53 +02:00
|
|
|
|
if (err) {
|
2020-04-30 15:48:06 +02:00
|
|
|
|
logger.error(err)
|
|
|
|
|
process.exit(1)
|
2017-10-23 23:13:53 +02:00
|
|
|
|
} else {
|
2020-04-30 15:48:06 +02:00
|
|
|
|
logger.info(`Listening on ${config.hostname}:${config.port}.`)
|
2017-10-23 23:13:53 +02:00
|
|
|
|
}
|
|
|
|
|
})
|