Node 10+ 💥, db-hafas@3, update deps & dev deps

- db-stations@3
- hafas-client-health-check@2
- hafas-rest-api@3
- add pino-pretty@4 for debug logging
This commit is contained in:
Jannis R 2020-04-30 15:48:06 +02:00
parent cf8a00dd53
commit a47e20c1d4
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 49 additions and 21 deletions

View file

@ -7,9 +7,8 @@ const createApi = require('hafas-rest-api')
const createHealthCheck = require('hafas-client-health-check')
const pkg = require('./package.json')
const stations = require('./lib/stations')
const allStations = require('./lib/all-stations')
const station = require('./lib/station')
const stations = require('./routes/stations')
const station = require('./routes/station')
const docsAsMarkdown = readFileSync(join(__dirname, 'docs', 'index.md'), {encoding: 'utf8'})
@ -18,6 +17,12 @@ const hafas = createHafas(pkg.name)
const berlinHbf = '8011160'
const healthCheck = createHealthCheck(hafas, berlinHbf)
const modifyRoutes = (routes) => {
routes['/stations'] = stations
routes['/stations/:id'] = station
return routes
}
const config = {
hostname: process.env.HOSTNAME || 'localhost',
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
@ -25,26 +30,23 @@ const config = {
description: pkg.description,
homepage: pkg.homepage,
version: pkg.version,
docsAsMarkdown,
docsLink: '/docs',
logging: true,
healthCheck,
aboutPage: true,
docsAsMarkdown
etags: 'strong',
healthCheck,
modifyRoutes,
}
const attachAdditionalHandlers = (api) => {
api.get('/stations', stations)
api.get('/stations/all', allStations)
api.get('/stations/:id', station)
}
const api = createApi(hafas, config, attachAdditionalHandlers)
const api = createApi(hafas, config, () => {})
api.listen(config.port, (err) => {
const {logger} = api.locals
if (err) {
console.error(err)
process.exitCode = 1
logger.error(err)
process.exit(1)
} else {
console.info(`Listening on ${config.hostname}:${config.port}.`)
logger.info(`Listening on ${config.hostname}:${config.port}.`)
}
})

View file

@ -19,18 +19,21 @@
"db"
],
"engines": {
"node": ">=6"
"node": ">=10"
},
"dependencies": {
"cli-native": "^1.0.0",
"db-hafas": "^3.0.1",
"db-stations": "^2.4.0",
"db-stations-autocomplete": "^2.1.0",
"db-hafas": "^5.0.2",
"db-stations": "^3.0.0",
"db-stations-autocomplete": "^2.2.0",
"etag": "^1.8.1",
"hafas-client-health-check": "^1.0.1",
"hafas-rest-api": "^1.2.1",
"hafas-client-health-check": "^2.1.1",
"hafas-rest-api": "^3.3.0",
"serve-buffer": "^2.0.0"
},
"devDependencies": {
"pino-pretty": "^4.0.0"
},
"scripts": {
"start": "node index.js"
}

View file

@ -109,4 +109,27 @@ const stationsRoute = (req, res, next) => {
.catch(next)
}
stationsRoute.queryParameters = {
query: {
description: 'Find stations by name using [`db-stations-autocomplete`](https://npmjs.com/package/db-stations-autocomplete).',
type: 'string',
defaultStr: '',
},
limit: {
description: '*If `query` is used:* Return at most `n` stations.',
type: 'number',
default: 3,
},
fuzzy: {
description: '*If `query` is used:* Find stations despite typos.',
type: 'boolean',
default: false,
},
completion: {
description: '*If `query` is used:* Autocomplete stations.',
type: 'boolean',
default: true,
},
}
module.exports = stationsRoute