diff --git a/lib/render.js b/lib/render.js index a759f1345d..04158e5d3c 100644 --- a/lib/render.js +++ b/lib/render.js @@ -13,14 +13,16 @@ export function render (req, res) { } /* istanbul ignore if */ if (!this.renderer) { - setTimeout(() => { - this.render(req, res) - }, 1000) - return + return new Promise((resolve) => { + setTimeout(() => { + resolve(this.render(req, res)) + }, 1000) + }) } const self = this const context = getContext(req, res) return co(function * () { + res.statusCode = 200 if (self.dev) { // Call webpack middleware only in development yield self.webpackDevMiddleware(req, res) @@ -34,9 +36,9 @@ export function render (req, res) { // Serve static/ files yield self.serveStatic(req, res) // Serve .nuxt/dist/ files (only for production) - if (!self.dev && self._nuxtRegexp.test(req.url)) { + if (!self.dev && self.options.nuxtStatic && req.url.indexOf(self.options.build.publicPath) === 0) { const url = req.url - req.url = req.url.replace(self._nuxtRegexp, '/') + req.url = req.url.replace(self.options.build.publicPath, '/') yield self.serveStaticNuxt(req, res) /* istanbul ignore next */ req.url = url @@ -44,7 +46,7 @@ export function render (req, res) { }) .then(() => { /* istanbul ignore if */ - if (this.dev && this._nuxtRegexp.test(req.url) && req.url.includes('.hot-update.json')) { + if (this.dev && req.url.indexOf(self.options.build.publicPath) === 0 && req.url.includes('.hot-update.json')) { res.statusCode = 404 return res.end() } @@ -57,10 +59,12 @@ export function render (req, res) { res.setHeader('Content-Type', 'text/html; charset=utf-8') res.setHeader('Content-Length', Buffer.byteLength(html)) res.end(html, 'utf8') + return html }) .catch((err) => { res.statusCode = 500 res.end(this.errorTemplate({ err }), 'utf8') + return err }) } @@ -76,15 +80,16 @@ export function renderRoute (url, context = {}) { if (!context.nuxt.serverRendered) { app = '
' } + const publicPath = self.options.build.publicPath.indexOf('http') === 0 ? self.options.build.publicPath : urlJoin(self.options.router.base, self.options.build.publicPath) const html = self.appTemplate({ dev: self.dev, // Use to add the extracted CSS in production baseUrl: self.options.router.base, APP: app, context: context, files: { - css: urlJoin(self.options.router.base, '/_nuxt/', self.options.build.filenames.css), - vendor: urlJoin(self.options.router.base, '/_nuxt/', self.options.build.filenames.vendor), - app: urlJoin(self.options.router.base, '/_nuxt/', self.options.build.filenames.app) + css: urlJoin(publicPath, self.options.build.filenames.css), + vendor: urlJoin(publicPath, self.options.build.filenames.vendor), + app: urlJoin(publicPath, self.options.build.filenames.app) } }) return {