mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 16:43:55 +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 */
|
||||
if (!this.renderer) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
this.render(req, res)
|
||||
resolve(this.render(req, res))
|
||||
}, 1000)
|
||||
return
|
||||
})
|
||||
}
|
||||
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 = '<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({
|
||||
dev: self.dev, // Use to add the extracted CSS <link> 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user