Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async render fixes for #1170 #1172

Merged
merged 1 commit into from
Feb 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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)
Expand Down