db-hafas@3, hafas-rest-api@1
This commit is contained in:
parent
d9c4e9468a
commit
1e4de0a3ff
2 changed files with 17 additions and 6 deletions
19
index.js
19
index.js
|
@ -1,6 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const hafas = require('db-hafas')
|
const createHafas = require('db-hafas')
|
||||||
const createApi = require('hafas-rest-api')
|
const createApi = require('hafas-rest-api')
|
||||||
|
|
||||||
const pkg = require('./package.json')
|
const pkg = require('./package.json')
|
||||||
|
@ -8,22 +8,33 @@ const stations = require('./lib/stations')
|
||||||
const allStations = require('./lib/all-stations')
|
const allStations = require('./lib/all-stations')
|
||||||
const station = require('./lib/station')
|
const station = require('./lib/station')
|
||||||
|
|
||||||
|
const hafas = createHafas(pkg.name)
|
||||||
|
|
||||||
|
const healthCheck = () => {
|
||||||
|
return hafas.station('8011306')
|
||||||
|
.then(st => !!st)
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
hostname: process.env.HOSTNAME || '2.db.transport.rest',
|
hostname: process.env.HOSTNAME || '2.db.transport.rest',
|
||||||
port: process.env.PORT || 3000,
|
port: process.env.PORT || 3000,
|
||||||
name: pkg.name,
|
name: pkg.name,
|
||||||
description: pkg.description,
|
description: pkg.description,
|
||||||
homepage: pkg.homepage,
|
homepage: pkg.homepage,
|
||||||
docsLink: 'https://github.com/derhuerst/db-rest/blob/master/docs/index.md',
|
version: pkg.version,
|
||||||
|
docsLink: 'https://github.com/derhuerst/db-rest/blob/2/docs/index.md',
|
||||||
logging: true,
|
logging: true,
|
||||||
|
healthCheck,
|
||||||
aboutPage: true
|
aboutPage: true
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = createApi(hafas, config, (api) => {
|
const attachAdditionalHandlers = (api) => {
|
||||||
api.get('/stations', stations)
|
api.get('/stations', stations)
|
||||||
api.get('/stations/all', allStations)
|
api.get('/stations/all', allStations)
|
||||||
api.get('/stations/:id', station)
|
api.get('/stations/:id', station)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
const api = createApi(hafas, config, attachAdditionalHandlers)
|
||||||
|
|
||||||
api.listen(config.port, (err) => {
|
api.listen(config.port, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -28,10 +28,10 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cli-native": "^1.0.0",
|
"cli-native": "^1.0.0",
|
||||||
"db-hafas": "^2.1.0",
|
"db-hafas": "^3.0.1",
|
||||||
"db-stations": "^2.4.0",
|
"db-stations": "^2.4.0",
|
||||||
"db-stations-autocomplete": "^2.1.0",
|
"db-stations-autocomplete": "^2.1.0",
|
||||||
"hafas-rest-api": "^0.5.0",
|
"hafas-rest-api": "^1.1.0",
|
||||||
"ndjson": "^1.5.0"
|
"ndjson": "^1.5.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in a new issue