mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
The change in #1155 to remove server-side gzipping changed static rendering to no longer return a promise, which broke the Hapi example that was waiting for a resolved promise before closing the request. This PR fixes up all render or serve methods of server.js to consistently either await and/or return. Additionally, it collapses serveStatic and _serveStatic, as _serveStatic no longer needs to be factored out.
This commit is contained in:
parent
8a5250985f
commit
47d57f4bcd
|
@ -157,7 +157,7 @@ export default class Server {
|
|||
res.setHeader('X-Powered-By', `Next.js ${pkg.version}`)
|
||||
}
|
||||
const html = await this.renderToHTML(req, res, pathname, query)
|
||||
sendHTML(res, html, req.method)
|
||||
return sendHTML(res, html, req.method)
|
||||
}
|
||||
|
||||
async renderToHTML (req, res, pathname, query) {
|
||||
|
@ -185,7 +185,7 @@ export default class Server {
|
|||
|
||||
async renderError (err, req, res, pathname, query) {
|
||||
const html = await this.renderErrorToHTML(err, req, res, pathname, query)
|
||||
sendHTML(res, html, req.method)
|
||||
return sendHTML(res, html, req.method)
|
||||
}
|
||||
|
||||
async renderErrorToHTML (err, req, res, pathname, query) {
|
||||
|
@ -213,7 +213,7 @@ export default class Server {
|
|||
async render404 (req, res, parsedUrl = parse(req.url, true)) {
|
||||
const { pathname, query } = parsedUrl
|
||||
res.statusCode = 404
|
||||
this.renderError(null, req, res, pathname, query)
|
||||
return this.renderError(null, req, res, pathname, query)
|
||||
}
|
||||
|
||||
async renderJSON (req, res, page) {
|
||||
|
@ -225,7 +225,7 @@ export default class Server {
|
|||
}
|
||||
|
||||
try {
|
||||
await renderJSON(req, res, page, this.renderOpts)
|
||||
return await renderJSON(req, res, page, this.renderOpts)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
res.statusCode = 404
|
||||
|
@ -250,15 +250,9 @@ export default class Server {
|
|||
return renderErrorJSON(err, req, res, this.renderOpts)
|
||||
}
|
||||
|
||||
serveStatic (req, res, path) {
|
||||
this._serveStatic(req, res, () => {
|
||||
return serveStatic(req, res, path)
|
||||
})
|
||||
}
|
||||
|
||||
async _serveStatic (req, res, fn) {
|
||||
async serveStatic (req, res, path) {
|
||||
try {
|
||||
await fn()
|
||||
return await serveStatic(req, res, path)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
this.render404(req, res)
|
||||
|
|
Loading…
Reference in a new issue