mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
check if response is already sent (#569)
This commit is contained in:
parent
0f11018819
commit
c210a2e73c
|
@ -108,12 +108,16 @@ export async function renderErrorJSON (err, res, { dir = process.cwd(), dev = fa
|
|||
}
|
||||
|
||||
export function sendHTML (res, html) {
|
||||
if (res.finished) return
|
||||
|
||||
res.setHeader('Content-Type', 'text/html')
|
||||
res.setHeader('Content-Length', Buffer.byteLength(html))
|
||||
res.end(html)
|
||||
}
|
||||
|
||||
export function sendJSON (res, obj) {
|
||||
if (res.finished) return
|
||||
|
||||
const json = JSON.stringify(obj)
|
||||
res.setHeader('Content-Type', 'application/json')
|
||||
res.setHeader('Content-Length', Buffer.byteLength(json))
|
||||
|
|
Loading…
Reference in a new issue