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:
parent
cf8a00dd53
commit
a47e20c1d4
3 changed files with 49 additions and 21 deletions
32
index.js
32
index.js
|
@ -7,9 +7,8 @@ const createApi = require('hafas-rest-api')
|
||||||
const createHealthCheck = require('hafas-client-health-check')
|
const createHealthCheck = require('hafas-client-health-check')
|
||||||
|
|
||||||
const pkg = require('./package.json')
|
const pkg = require('./package.json')
|
||||||
const stations = require('./lib/stations')
|
const stations = require('./routes/stations')
|
||||||
const allStations = require('./lib/all-stations')
|
const station = require('./routes/station')
|
||||||
const station = require('./lib/station')
|
|
||||||
|
|
||||||
const docsAsMarkdown = readFileSync(join(__dirname, 'docs', 'index.md'), {encoding: 'utf8'})
|
const docsAsMarkdown = readFileSync(join(__dirname, 'docs', 'index.md'), {encoding: 'utf8'})
|
||||||
|
|
||||||
|
@ -18,6 +17,12 @@ const hafas = createHafas(pkg.name)
|
||||||
const berlinHbf = '8011160'
|
const berlinHbf = '8011160'
|
||||||
const healthCheck = createHealthCheck(hafas, berlinHbf)
|
const healthCheck = createHealthCheck(hafas, berlinHbf)
|
||||||
|
|
||||||
|
const modifyRoutes = (routes) => {
|
||||||
|
routes['/stations'] = stations
|
||||||
|
routes['/stations/:id'] = station
|
||||||
|
return routes
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
hostname: process.env.HOSTNAME || 'localhost',
|
hostname: process.env.HOSTNAME || 'localhost',
|
||||||
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
|
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
|
||||||
|
@ -25,26 +30,23 @@ const config = {
|
||||||
description: pkg.description,
|
description: pkg.description,
|
||||||
homepage: pkg.homepage,
|
homepage: pkg.homepage,
|
||||||
version: pkg.version,
|
version: pkg.version,
|
||||||
|
docsAsMarkdown,
|
||||||
docsLink: '/docs',
|
docsLink: '/docs',
|
||||||
logging: true,
|
logging: true,
|
||||||
healthCheck,
|
|
||||||
aboutPage: true,
|
aboutPage: true,
|
||||||
docsAsMarkdown
|
etags: 'strong',
|
||||||
|
healthCheck,
|
||||||
|
modifyRoutes,
|
||||||
}
|
}
|
||||||
|
|
||||||
const attachAdditionalHandlers = (api) => {
|
const api = createApi(hafas, config, () => {})
|
||||||
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) => {
|
api.listen(config.port, (err) => {
|
||||||
|
const {logger} = api.locals
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err)
|
logger.error(err)
|
||||||
process.exitCode = 1
|
process.exit(1)
|
||||||
} else {
|
} else {
|
||||||
console.info(`Listening on ${config.hostname}:${config.port}.`)
|
logger.info(`Listening on ${config.hostname}:${config.port}.`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
15
package.json
15
package.json
|
@ -19,18 +19,21 @@
|
||||||
"db"
|
"db"
|
||||||
],
|
],
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=10"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cli-native": "^1.0.0",
|
"cli-native": "^1.0.0",
|
||||||
"db-hafas": "^3.0.1",
|
"db-hafas": "^5.0.2",
|
||||||
"db-stations": "^2.4.0",
|
"db-stations": "^3.0.0",
|
||||||
"db-stations-autocomplete": "^2.1.0",
|
"db-stations-autocomplete": "^2.2.0",
|
||||||
"etag": "^1.8.1",
|
"etag": "^1.8.1",
|
||||||
"hafas-client-health-check": "^1.0.1",
|
"hafas-client-health-check": "^2.1.1",
|
||||||
"hafas-rest-api": "^1.2.1",
|
"hafas-rest-api": "^3.3.0",
|
||||||
"serve-buffer": "^2.0.0"
|
"serve-buffer": "^2.0.0"
|
||||||
},
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"pino-pretty": "^4.0.0"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js"
|
"start": "node index.js"
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,4 +109,27 @@ const stationsRoute = (req, res, next) => {
|
||||||
.catch(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
|
module.exports = stationsRoute
|
||||||
|
|
Loading…
Reference in a new issue