mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 21:10:38 +00:00
Set publicPath and render always returns a promise
This commit is contained in:
parent
4c53c6a669
commit
5a500b6735
@ -13,14 +13,16 @@ export function render (req, res) {
|
|||||||
}
|
}
|
||||||
/* istanbul ignore if */
|
/* istanbul ignore if */
|
||||||
if (!this.renderer) {
|
if (!this.renderer) {
|
||||||
setTimeout(() => {
|
return new Promise((resolve) => {
|
||||||
this.render(req, res)
|
setTimeout(() => {
|
||||||
}, 1000)
|
resolve(this.render(req, res))
|
||||||
return
|
}, 1000)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
const self = this
|
const self = this
|
||||||
const context = getContext(req, res)
|
const context = getContext(req, res)
|
||||||
return co(function * () {
|
return co(function * () {
|
||||||
|
res.statusCode = 200
|
||||||
if (self.dev) {
|
if (self.dev) {
|
||||||
// Call webpack middleware only in development
|
// Call webpack middleware only in development
|
||||||
yield self.webpackDevMiddleware(req, res)
|
yield self.webpackDevMiddleware(req, res)
|
||||||
@ -34,9 +36,9 @@ export function render (req, res) {
|
|||||||
// Serve static/ files
|
// Serve static/ files
|
||||||
yield self.serveStatic(req, res)
|
yield self.serveStatic(req, res)
|
||||||
// Serve .nuxt/dist/ files (only for production)
|
// 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
|
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)
|
yield self.serveStaticNuxt(req, res)
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
req.url = url
|
req.url = url
|
||||||
@ -44,7 +46,7 @@ export function render (req, res) {
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
/* istanbul ignore if */
|
/* 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
|
res.statusCode = 404
|
||||||
return res.end()
|
return res.end()
|
||||||
}
|
}
|
||||||
@ -57,10 +59,12 @@ export function render (req, res) {
|
|||||||
res.setHeader('Content-Type', 'text/html; charset=utf-8')
|
res.setHeader('Content-Type', 'text/html; charset=utf-8')
|
||||||
res.setHeader('Content-Length', Buffer.byteLength(html))
|
res.setHeader('Content-Length', Buffer.byteLength(html))
|
||||||
res.end(html, 'utf8')
|
res.end(html, 'utf8')
|
||||||
|
return html
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
res.statusCode = 500
|
res.statusCode = 500
|
||||||
res.end(this.errorTemplate({ err }), 'utf8')
|
res.end(this.errorTemplate({ err }), 'utf8')
|
||||||
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,15 +80,16 @@ export function renderRoute (url, context = {}) {
|
|||||||
if (!context.nuxt.serverRendered) {
|
if (!context.nuxt.serverRendered) {
|
||||||
app = '<div id="__nuxt"></div>'
|
app = '<div id="__nuxt"></div>'
|
||||||
}
|
}
|
||||||
|
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({
|
const html = self.appTemplate({
|
||||||
dev: self.dev, // Use to add the extracted CSS <link> in production
|
dev: self.dev, // Use to add the extracted CSS <link> in production
|
||||||
baseUrl: self.options.router.base,
|
baseUrl: self.options.router.base,
|
||||||
APP: app,
|
APP: app,
|
||||||
context: context,
|
context: context,
|
||||||
files: {
|
files: {
|
||||||
css: urlJoin(self.options.router.base, '/_nuxt/', self.options.build.filenames.css),
|
css: urlJoin(publicPath, self.options.build.filenames.css),
|
||||||
vendor: urlJoin(self.options.router.base, '/_nuxt/', self.options.build.filenames.vendor),
|
vendor: urlJoin(publicPath, self.options.build.filenames.vendor),
|
||||||
app: urlJoin(self.options.router.base, '/_nuxt/', self.options.build.filenames.app)
|
app: urlJoin(publicPath, self.options.build.filenames.app)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user