diff --git a/routes/stations.js b/routes/stations.js index 37df43a..5934980 100644 --- a/routes/stations.js +++ b/routes/stations.js @@ -95,10 +95,15 @@ const stationsRoute = (req, res, next) => { pAllStations .then(({stations, timeModified, asJson, asNdjson}) => { res.setHeader('Last-Modified', timeModified.toUTCString()) + res.setHeader('Content-Type', t) if (Object.keys(q).length === 0) { const data = t === JSON_MIME ? asJson.data : asNdjson.data const etag = t === JSON_MIME ? asJson.etag : asNdjson.etag - serveBuffer(req, res, data, {timeModified, etag}) + serveBuffer(req, res, data, { + timeModified, + etag, + contentType: t, + }) } else if (q.query) { complete(req, res, next, q, stations, onStation, onEnd) } else { diff --git a/test/index.js b/test/index.js index a00c7c8..718dea9 100644 --- a/test/index.js +++ b/test/index.js @@ -39,3 +39,43 @@ tape.test('/journeys?loyaltyCard works', async (t) => { } }, {}, '/journeys?from=123&to=234&loyaltyCard=bahncard-2nd-50') }) + +tape.test('/stations works', async (t) => { + { + const {headers} = await fetchWithTestApi({}, {}, '/stations', { + headers: { + 'accept': 'application/json', + }, + }) + t.equal(headers['content-type'], 'application/json') + } + + { + const {headers} = await fetchWithTestApi({}, {}, '/stations', { + headers: { + 'accept': 'application/x-ndjson', + }, + }) + t.equal(headers['content-type'], 'application/x-ndjson') + } +}) + +tape.test('/stations?query=frankf works', async (t) => { + { + const {headers} = await fetchWithTestApi({}, {}, '/stations?query=frankf', { + headers: { + 'accept': 'application/json', + }, + }) + t.equal(headers['content-type'], 'application/json') + } + + { + const {headers} = await fetchWithTestApi({}, {}, '/stations?query=frankf', { + headers: { + 'accept': 'application/x-ndjson', + }, + }) + t.equal(headers['content-type'], 'application/x-ndjson') + } +})