Skip to content

Commit d544422

Browse files
jon-cookegergelyke
authored andcommitted
feat(response): add content-type header to JSON responses (#80)
1 parent 3998573 commit d544422

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/terminus.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function noopResolves () {
1717

1818
function sendSuccess (res, info) {
1919
res.statusCode = 200
20+
res.setHeader('Content-Type', 'application/json')
2021
if (info) {
2122
return res.end(JSON.stringify({
2223
status: 'ok',
@@ -28,6 +29,7 @@ function sendSuccess (res, info) {
2829

2930
function sendFailure (res) {
3031
res.statusCode = 503
32+
res.setHeader('Content-Type', 'application/json')
3133
res.end(FAILURE_RESPONSE)
3234
}
3335

lib/terminus.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ describe('Terminus', () => {
4848
fetch('http://localhost:8000/health')
4949
.then(res => {
5050
expect(res.status).to.eql(200)
51+
expect(res.headers.has('Content-Type')).to.eql(true)
52+
expect(res.headers.get('Content-Type')).to.eql('application/json')
5153
expect(onHealthCheckRan).to.eql(true)
5254
done()
5355
})
@@ -72,6 +74,8 @@ describe('Terminus', () => {
7274
fetch('http://localhost:8000/health')
7375
.then(res => {
7476
expect(res.status).to.eql(200)
77+
expect(res.headers.has('Content-Type')).to.eql(true)
78+
expect(res.headers.get('Content-Type')).to.eql('application/json')
7579
expect(onHealthCheckRan).to.eql(true)
7680
return res.json()
7781
})

0 commit comments

Comments
 (0)