diff --git a/lib/nuxt.js b/lib/nuxt.js index 6415885000..a7f04242ae 100644 --- a/lib/nuxt.js +++ b/lib/nuxt.js @@ -42,7 +42,6 @@ class Nuxt { router: { mode: 'history', base: '/', - userSpecifiedBase: false, middleware: [], linkActiveClass: 'nuxt-link-active', linkExactActiveClass: 'nuxt-link-exact-active', @@ -63,7 +62,9 @@ class Nuxt { // Sanitization if (options.loading === true) delete options.loading if (options.router && typeof options.router.middleware === 'string') options.router.middleware = [ options.router.middleware ] - if (options.router && typeof options.router.base === 'string') options.router.userSpecifiedBase = true + if (options.router && typeof options.router.base === 'string') { + this._routerBaseSpecified = true + } if (typeof options.transition === 'string') options.transition = { name: options.transition } this.options = _.defaultsDeep(options, defaults) // Env variables diff --git a/lib/render.js b/lib/render.js index 66d7fbf960..467ec9099c 100644 --- a/lib/render.js +++ b/lib/render.js @@ -22,34 +22,33 @@ export async function render (req, res) { }, 1000) }) } - const self = this const context = getContext(req, res) res.statusCode = 200 try { - if (self.dev) { + if (this.dev) { // Call webpack middleware only in development - await self.webpackDevMiddleware(req, res) - await self.webpackHotMiddleware(req, res) + await this.webpackDevMiddleware(req, res) + await this.webpackHotMiddleware(req, res) } - if (!self.dev && self.options.performance.gzip) { - await self.gzipMiddleware(req, res) + if (!this.dev && this.options.performance.gzip) { + await this.gzipMiddleware(req, res) } // If base in req.url, remove it for the middleware and vue-router - if (self.options.router.base !== '/' && req.url.indexOf(self.options.router.base) === 0) { + if (this.options.router.base !== '/' && req.url.indexOf(this.options.router.base) === 0) { // Compatibility with base url for dev server - req.url = req.url.replace(self.options.router.base, '/') + req.url = req.url.replace(this.options.router.base, '/') } // Serve static/ files - await self.serveStatic(req, res) + await this.serveStatic(req, res) // Serve .nuxt/dist/ files (only for production) - if (!self.dev && req.url.indexOf(self.options.build.publicPath) === 0) { + if (!this.dev && req.url.indexOf(this.options.build.publicPath) === 0) { const url = req.url - req.url = req.url.replace(self.options.build.publicPath, '/') - await self.serveStaticNuxt(req, res) + req.url = req.url.replace(this.options.build.publicPath, '/') + await this.serveStaticNuxt(req, res) /* istanbul ignore next */ req.url = url } - if (this.dev && req.url.indexOf(self.options.build.publicPath) === 0 && req.url.includes('.hot-update.json')) { + if (this.dev && req.url.indexOf(this.options.build.publicPath) === 0 && req.url.includes('.hot-update.json')) { res.statusCode = 404 return res.end() } @@ -87,20 +86,19 @@ export async function renderRoute (url, context = {}) { context.url = url context.isServer = true // Call renderToString from the bundleRenderer and generate the HTML (will update the context as well) - const self = this - let APP = await self.renderToString(context) + let APP = await this.renderToString(context) if (!context.nuxt.serverRendered) { APP = '
' } const m = context.meta.inject() let HEAD = m.meta.text() + m.title.text() + m.link.text() + m.style.text() + m.script.text() + m.noscript.text() - if (self.options.router.userSpecifiedBase) { - HEAD += `` + if (this._routerBaseSpecified) { + HEAD += `` } HEAD += context.renderResourceHints() + context.renderStyles() APP += `` APP += context.renderScripts() - const html = self.appTemplate({ + const html = this.appTemplate({ HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(), BODY_ATTRS: m.bodyAttrs.text(), HEAD,