db-rest/index.js

38 lines
877 B
JavaScript
Raw Normal View History

2017-10-23 23:13:53 +02:00
'use strict'
2017-12-16 09:06:35 +01:00
const hafas = require('hafas-client')
const dbProfile = require('hafas-client/p/db')
const createApi = require('hafas-rest-api')
const createLogging = require('hafas-rest-api/logging')
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')
2017-10-23 23:13:53 +02:00
2017-12-16 09:06:35 +01:00
const config = {
hostname: process.env.HOSTNAME || '1.db.transport.rest',
port: process.env.PORT || 3000,
name: pkg.name,
homepage: pkg.homepage
}
2017-10-23 23:13:53 +02:00
2017-12-16 09:06:35 +01:00
const client = hafas(dbProfile)
const api = createApi(client, config)
api.use(createLogging())
api.get('/stations', stations)
api.get('/stations/all', allStations)
module.exports = api
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
}
})