diff --git a/index.js b/index.js index a341354..f9efde3 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict' -const hafas = require('db-hafas') +const createHafas = require('db-hafas') const createApi = require('hafas-rest-api') const pkg = require('./package.json') @@ -8,22 +8,33 @@ const stations = require('./lib/stations') const allStations = require('./lib/all-stations') const station = require('./lib/station') +const hafas = createHafas(pkg.name) + +const healthCheck = () => { + return hafas.station('8011306') + .then(st => !!st) +} + const config = { hostname: process.env.HOSTNAME || '2.db.transport.rest', port: process.env.PORT || 3000, name: pkg.name, description: pkg.description, 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, + healthCheck, aboutPage: true } -const api = createApi(hafas, config, (api) => { +const attachAdditionalHandlers = (api) => { api.get('/stations', stations) api.get('/stations/all', allStations) api.get('/stations/:id', station) -}) +} + +const api = createApi(hafas, config, attachAdditionalHandlers) api.listen(config.port, (err) => { if (err) { diff --git a/package.json b/package.json index 2454d9e..c368f7f 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,10 @@ }, "dependencies": { "cli-native": "^1.0.0", - "db-hafas": "^2.1.0", + "db-hafas": "^3.0.1", "db-stations": "^2.4.0", "db-stations-autocomplete": "^2.1.0", - "hafas-rest-api": "^0.5.0", + "hafas-rest-api": "^1.1.0", "ndjson": "^1.5.0" }, "scripts": {