From 1e4de0a3ff5dc79a6ee3e0a530ad11698601ee14 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 25 Oct 2018 21:49:17 +0200 Subject: [PATCH] db-hafas@3, hafas-rest-api@1 --- index.js | 19 +++++++++++++++---- package.json | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) 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": {