fix: dont serve index.html when url is / and remove publicPath in production

This commit is contained in:
Sébastien Chopin 2017-06-20 09:13:24 +02:00
parent 0b4b46c91e
commit bf379fc0fd
2 changed files with 5 additions and 5 deletions

View File

@ -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
}))
}

View File

@ -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
}