From 9d1aff0f891851ace2e6eba02885756a588b4173 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 25 Feb 2018 00:03:42 +0100 Subject: [PATCH] fix /stations/all :bug: Although this is a breaking change, it changes the API to behave as documented. :( --- lib/all-stations.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/all-stations.js b/lib/all-stations.js index 209bf35..5bc9e1d 100644 --- a/lib/all-stations.js +++ b/lib/all-stations.js @@ -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