Last active
October 27, 2016 12:06
-
-
Save alanshaw/133562ace098870f2d178295b0ea7068 to your computer and use it in GitHub Desktop.
Mock JSON server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Http = require('http') | |
function createMockJsonServer ({ statusCode = 200, body, headers = {} }) { | |
return Http.createServer((req, res) => { | |
res.statusCode = statusCode | |
res.setHeader('Content-Type', 'application/json') | |
Object.keys(headers).forEach((k) => res.setHeader(k, headers[k])) | |
if (body) res.write(JSON.stringify(body)) | |
res.end() | |
}) | |
} | |
module.exports = createMockJsonServer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment