Commit c210a2e7 authored by Naoyuki Kanezawa's avatar Naoyuki Kanezawa Committed by Guillermo Rauch

check if response is already sent (#569)

parent 0f110188
...@@ -108,12 +108,16 @@ export async function renderErrorJSON (err, res, { dir = process.cwd(), dev = fa ...@@ -108,12 +108,16 @@ export async function renderErrorJSON (err, res, { dir = process.cwd(), dev = fa
} }
export function sendHTML (res, html) { export function sendHTML (res, html) {
if (res.finished) return
res.setHeader('Content-Type', 'text/html') res.setHeader('Content-Type', 'text/html')
res.setHeader('Content-Length', Buffer.byteLength(html)) res.setHeader('Content-Length', Buffer.byteLength(html))
res.end(html) res.end(html)
} }
export function sendJSON (res, obj) { export function sendJSON (res, obj) {
if (res.finished) return
const json = JSON.stringify(obj) const json = JSON.stringify(obj)
res.setHeader('Content-Type', 'application/json') res.setHeader('Content-Type', 'application/json')
res.setHeader('Content-Length', Buffer.byteLength(json)) res.setHeader('Content-Length', Buffer.byteLength(json))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment