diff --git a/lib/nuxt.js b/lib/nuxt.js index a2c8f3c316..7bcc259f6f 100644 --- a/lib/nuxt.js +++ b/lib/nuxt.js @@ -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 diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index ae0609669c..f9e56aa032 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -37,5 +37,10 @@ module.exports = { }, css: [ { src: '~/assets/app.css' } - ] + ], + render: { + static: { + maxAge: '1y' + } + } } diff --git a/test/fixtures/with-config/static/test.txt b/test/fixtures/with-config/static/test.txt new file mode 100644 index 0000000000..2913997fe4 --- /dev/null +++ b/test/fixtures/with-config/static/test.txt @@ -0,0 +1 @@ +A test here :) diff --git a/test/with-config.test.js b/test/with-config.test.js index f93455bd4d..bbce95a138 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -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()