mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
fix: dont serve index.html when url is / and remove publicPath in production
This commit is contained in:
parent
0b4b46c91e
commit
bf379fc0fd
@ -10,7 +10,7 @@ import _ from 'lodash'
|
|||||||
import { join, resolve } from 'path'
|
import { join, resolve } from 'path'
|
||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
import { createBundleRenderer } from 'vue-server-renderer'
|
import { createBundleRenderer } from 'vue-server-renderer'
|
||||||
import { encodeHtml, getContext, setAnsiColors, isUrl } from 'utils'
|
import { encodeHtml, getContext, setAnsiColors } from 'utils'
|
||||||
import Debug from 'debug'
|
import Debug from 'debug'
|
||||||
import connect from 'connect'
|
import connect from 'connect'
|
||||||
|
|
||||||
@ -205,8 +205,8 @@ export default class Renderer extends Tapable {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Remove publicPath from requests when it is pointing to CDN
|
// Remove publicPath from requests in production mode
|
||||||
if (isUrl(this.options.build.publicPath)) {
|
if (!this.options.dev) {
|
||||||
this.useMiddleware((req, res, next) => {
|
this.useMiddleware((req, res, next) => {
|
||||||
if (req.url.indexOf(this.options.build.publicPath) === 0) {
|
if (req.url.indexOf(this.options.build.publicPath) === 0) {
|
||||||
req.url = req.url.replace(this.options.build.publicPath, '/')
|
req.url = req.url.replace(this.options.build.publicPath, '/')
|
||||||
@ -239,6 +239,7 @@ export default class Renderer extends Tapable {
|
|||||||
// For dev they will be served with devMiddleware
|
// For dev they will be served with devMiddleware
|
||||||
if (!this.options.dev) {
|
if (!this.options.dev) {
|
||||||
this.useMiddleware(serveStatic(resolve(this.options.buildDir, 'dist'), {
|
this.useMiddleware(serveStatic(resolve(this.options.buildDir, 'dist'), {
|
||||||
|
index: false, // Don't serve index.html template
|
||||||
maxAge: (this.options.dev ? 0 : '1y') // 1 year in production
|
maxAge: (this.options.dev ? 0 : '1y') // 1 year in production
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,7 @@ class Server {
|
|||||||
return this._ready
|
return this._ready
|
||||||
}
|
}
|
||||||
|
|
||||||
this.render = this.nuxt.renderer.app
|
this.server = http.createServer(this.nuxt.render)
|
||||||
this.server = http.createServer(this.render)
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user