mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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 fs from 'fs-extra'
|
||||
import { createBundleRenderer } from 'vue-server-renderer'
|
||||
import { encodeHtml, getContext, setAnsiColors, isUrl } from 'utils'
|
||||
import { encodeHtml, getContext, setAnsiColors } from 'utils'
|
||||
import Debug from 'debug'
|
||||
import connect from 'connect'
|
||||
|
||||
@ -205,8 +205,8 @@ export default class Renderer extends Tapable {
|
||||
next()
|
||||
})
|
||||
|
||||
// Remove publicPath from requests when it is pointing to CDN
|
||||
if (isUrl(this.options.build.publicPath)) {
|
||||
// Remove publicPath from requests in production mode
|
||||
if (!this.options.dev) {
|
||||
this.useMiddleware((req, res, next) => {
|
||||
if (req.url.indexOf(this.options.build.publicPath) === 0) {
|
||||
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
|
||||
if (!this.options.dev) {
|
||||
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
|
||||
}))
|
||||
}
|
||||
|
@ -29,8 +29,7 @@ class Server {
|
||||
return this._ready
|
||||
}
|
||||
|
||||
this.render = this.nuxt.renderer.app
|
||||
this.server = http.createServer(this.render)
|
||||
this.server = http.createServer(this.nuxt.render)
|
||||
|
||||
return this
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user