db-rest/index.js
2018-01-09 00:06:26 +01:00

35 lines
793 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict'
const hafas = require('db-hafas')
const createApi = require('hafas-rest-api')
const createLogging = require('hafas-rest-api/logging')
const hsts = require('hsts')
const pkg = require('./package.json')
const stations = require('./lib/stations')
const allStations = require('./lib/all-stations')
const config = {
hostname: process.env.HOSTNAME || '1.db.transport.rest',
port: process.env.PORT || 3000,
name: pkg.name,
homepage: pkg.homepage
}
const api = createApi(hafas, config)
api.use(createLogging())
api.get('/stations', stations)
api.get('/stations/all', allStations)
module.exports = api
api.listen(config.port, (err) => {
if (err) {
console.error(err)
process.exitCode = 1
} else {
console.info(`Listening on ${config.hostname}:${config.port}.`)
}
})