fix /stations/all 🐛

Although this is a breaking change, it changes the API to behave
as documented. :(
This commit is contained in:
Jannis R 2018-02-25 00:03:42 +01:00
parent c33cc04f9f
commit 9d1aff0f89
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5

View file

@ -1,11 +1,27 @@
'use strict'
const file = require.resolve('db-stations/full.ndjson')
let raw = require('db-stations/full.json')
let data = {}
for (let key in raw) {
if (!Object.prototype.hasOwnProperty.call(raw, key)) continue
const station = Object.assign({}, raw[key]) // clone
// todo: remove this remapping (breaking change!)
station.coordinates = station.location
delete station.location
data[station.id] = station
}
data = JSON.stringify(data) + '\n'
raw = null
const allStations = (req, res, next) => {
res.sendFile(file, {
maxAge: 10 * 24 * 3600 * 1000 // 10 days
}, next)
// res.sendFile(rawPath, {
// maxAge: 10 * 24 * 3600 * 1000 // 10 days
// }, next)
res.set('content-type', 'application/json')
res.send(data)
}
module.exports = allStations