UNPKG

397 Btext/coffeescriptView Raw
1module.exports = (f) -> (req, res) ->
2 result = f req
3 json = JSON.stringify result
4 console.info 'send json', json.substring 0, 100
5
6 # remember: length is the number of bytes not the length of the string
7 length = Buffer.byteLength(json, 'utf8')
8 res.writeHead 200, {'Content-Type': 'application/json; charset=utf-8', 'Content-Length': length}
9 res.write json
10 res.end()