move bundleRenderer to renderRoute with proper timeout

This commit is contained in:
Pooya Parsa 2017-06-14 21:22:23 +04:30
parent 17d0082861
commit a00378102b

View File

@ -128,15 +128,6 @@ export default class Renderer extends Tapable {
} }
async render (req, res) { async render (req, res) {
/* istanbul ignore if */
if (!this.bundleRenderer || !this.resources.appTemplate) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(this.render(req, res))
}, 1000)
})
}
// Get context // Get context
const context = getContext(req, res) const context = getContext(req, res)
res.statusCode = 200 res.statusCode = 200
@ -240,7 +231,20 @@ export default class Renderer extends Tapable {
} }
} }
async renderRoute (url, context = {}) { async renderRoute (url, context = {}, ctr = 0) {
/* istanbul ignore if */
if (!this.bundleRenderer || !this.resources.appTemplate) {
if (ctr > 5) {
// Don't wait more than 5 seconds
return Promise.reject(new Error('bundleRenderer is not ready'))
}
return new Promise((resolve) => {
setTimeout(() => {
resolve(this.renderRoute(url, context, ctr++))
}, 1000)
})
}
// Log rendered url // Log rendered url
debug(`Rendering url ${url}`) debug(`Rendering url ${url}`)