2017-10-23 23:13:53 +02:00
|
|
|
|
'use strict'
|
|
|
|
|
|
2018-01-09 00:06:26 +01:00
|
|
|
|
const hafas = require('db-hafas')
|
2017-12-16 09:06:35 +01:00
|
|
|
|
const createApi = require('hafas-rest-api')
|
|
|
|
|
const hsts = require('hsts')
|
2017-10-23 23:13:53 +02:00
|
|
|
|
|
2017-12-16 09:06:35 +01:00
|
|
|
|
const pkg = require('./package.json')
|
|
|
|
|
const stations = require('./lib/stations')
|
|
|
|
|
const allStations = require('./lib/all-stations')
|
2018-01-09 16:51:42 +01:00
|
|
|
|
const station = require('./lib/station')
|
2017-10-23 23:13:53 +02:00
|
|
|
|
|
2017-12-16 09:06:35 +01:00
|
|
|
|
const config = {
|
2018-01-09 16:42:30 +01:00
|
|
|
|
hostname: process.env.HOSTNAME || '2.db.transport.rest',
|
2017-12-16 09:06:35 +01:00
|
|
|
|
port: process.env.PORT || 3000,
|
|
|
|
|
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-03-07 02:33:49 +01:00
|
|
|
|
docsLink: 'https://github.com/derhuerst/db-rest/blob/master/docs/index.md',
|
|
|
|
|
logging: true,
|
|
|
|
|
aboutPage: true
|
2017-12-16 09:06:35 +01:00
|
|
|
|
}
|
2017-10-23 23:13:53 +02:00
|
|
|
|
|
2018-01-09 16:42:30 +01:00
|
|
|
|
const api = createApi(hafas, config, (api) => {
|
|
|
|
|
api.get('/stations', stations)
|
|
|
|
|
api.get('/stations/all', allStations)
|
2018-01-09 16:51:42 +01:00
|
|
|
|
api.get('/stations/:id', station)
|
2018-01-09 16:42:30 +01:00
|
|
|
|
})
|
2017-12-16 09:06:35 +01:00
|
|
|
|
|
|
|
|
|
api.listen(config.port, (err) => {
|
2017-10-23 23:13:53 +02:00
|
|
|
|
if (err) {
|
|
|
|
|
console.error(err)
|
2017-12-16 09:06:35 +01:00
|
|
|
|
process.exitCode = 1
|
2017-10-23 23:13:53 +02:00
|
|
|
|
} else {
|
2017-12-16 09:06:35 +01:00
|
|
|
|
console.info(`Listening on ${config.hostname}:${config.port}.`)
|
2017-10-23 23:13:53 +02:00
|
|
|
|
}
|
|
|
|
|
})
|