mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Add render.static
option to customize serve-static
middleware
This commit is contained in:
parent
1f6c3a9a7b
commit
eaee5afbde
@ -50,6 +50,7 @@ class Nuxt {
|
||||
scrollBehavior: null
|
||||
},
|
||||
render: {
|
||||
static: {},
|
||||
gzip: {
|
||||
threshold: 0
|
||||
},
|
||||
@ -90,7 +91,7 @@ class Nuxt {
|
||||
// renderer used by Vue.js (via createBundleRenderer)
|
||||
this.renderer = null
|
||||
// For serving static/ files to /
|
||||
this.serveStatic = pify(serveStatic(resolve(this.srcDir, 'static')))
|
||||
this.serveStatic = pify(serveStatic(resolve(this.srcDir, 'static'), this.options.render.static))
|
||||
// For serving .nuxt/dist/ files (only when build.publicPath is not an URL)
|
||||
this.serveStaticNuxt = pify(serveStatic(resolve(this.dir, '.nuxt', 'dist'), {
|
||||
maxAge: (this.dev ? 0 : '1y') // 1 year in production
|
||||
|
7
test/fixtures/with-config/nuxt.config.js
vendored
7
test/fixtures/with-config/nuxt.config.js
vendored
@ -37,5 +37,10 @@ module.exports = {
|
||||
},
|
||||
css: [
|
||||
{ src: '~/assets/app.css' }
|
||||
]
|
||||
],
|
||||
render: {
|
||||
static: {
|
||||
maxAge: '1y'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
test/fixtures/with-config/static/test.txt
vendored
Normal file
1
test/fixtures/with-config/static/test.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
A test here :)
|
@ -1,5 +1,7 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
import rp from 'request-promise-native'
|
||||
|
||||
const port = 4007
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
|
||||
@ -91,6 +93,11 @@ test('Check stats.json generated by build.analyze', t => {
|
||||
t.is(stats.assets.length, 29)
|
||||
})
|
||||
|
||||
test('Check /test.txt with custom serve-static options', async t => {
|
||||
const { headers } = await rp(url('/test.txt'), { resolveWithFullResponse: true })
|
||||
t.is(headers['cache-control'], 'public, max-age=31536000')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
test.after('Closing server and nuxt.js', t => {
|
||||
server.close()
|
||||
|
Loading…
Reference in New Issue
Block a user