From 96b05de6350028c8a2a04528d16e4b7fbc6d12c0 Mon Sep 17 00:00:00 2001 From: cookej Date: Wed, 19 Sep 2018 14:27:22 +0100 Subject: [PATCH] Add content-type header on json responses. --- lib/terminus.js | 2 ++ lib/terminus.spec.js | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/terminus.js b/lib/terminus.js index 1462619..5d74383 100644 --- a/lib/terminus.js +++ b/lib/terminus.js @@ -17,6 +17,7 @@ function noopResolves () { function sendSuccess (res, info) { res.statusCode = 200 + res.setHeader('Content-Type', 'application/json') if (info) { return res.end(JSON.stringify({ status: 'ok', @@ -28,6 +29,7 @@ function sendSuccess (res, info) { function sendFailure (res) { res.statusCode = 503 + res.setHeader('Content-Type', 'application/json') res.end(FAILURE_RESPONSE) } diff --git a/lib/terminus.spec.js b/lib/terminus.spec.js index 559a071..6aad4d7 100644 --- a/lib/terminus.spec.js +++ b/lib/terminus.spec.js @@ -48,6 +48,8 @@ describe('Terminus', () => { fetch('http://localhost:8000/health') .then(res => { expect(res.status).to.eql(200) + expect(res.headers.has('Content-Type')).to.eql(true) + expect(res.headers.get('Content-Type')).to.eql('application/json') expect(onHealthCheckRan).to.eql(true) done() }) @@ -72,6 +74,8 @@ describe('Terminus', () => { fetch('http://localhost:8000/health') .then(res => { expect(res.status).to.eql(200) + expect(res.headers.has('Content-Type')).to.eql(true) + expect(res.headers.get('Content-Type')).to.eql('application/json') expect(onHealthCheckRan).to.eql(true) return res.json() }) -- 2.17.1 (Apple Git-112)