diff --git a/lib/plugin.template.js b/lib/plugin.template.js index 4dc46d6..448065e 100755 --- a/lib/plugin.template.js +++ b/lib/plugin.template.js @@ -168,10 +168,6 @@ export default (ctx, inject) => { patch: {} } - if (process.server) { - headers.common['Accept-Encoding'] = 'gzip, deflate' - } - const axiosOptions = { baseURL, headers @@ -183,6 +179,11 @@ export default (ctx, inject) => { <% for (let h of options.proxyHeadersIgnore) { %>delete axiosOptions.headers.common['<%= h %>'] <% } %><% } %> + if (process.server) { + // Don't accept brotli encoding because Node can't parse it + axiosOptions.headers.common['Accept-Encoding'] = 'gzip, deflate' + } + // Create new axios instance const axios = Axios.create(axiosOptions) diff --git a/test/axios.test.js b/test/axios.test.js index 9e884f2..f04464a 100644 --- a/test/axios.test.js +++ b/test/axios.test.js @@ -76,4 +76,17 @@ describe('axios module', () => { expect(d).not.toBeNull() expect(b).not.toBe(d) }) + + test('ssr no brotli', async () => { + const makeReq = login => + axios + .get(url('/ssr' + (login ? '?login' : ''))) + .then(r => r.data) + .then(h => /encoding-\$(.*)\$/.exec(h)) + .then(m => (m && m[1] ? m[1] : null)) + + const result = await makeReq() + + expect(result).toBe('gzip, deflate') + }) }) diff --git a/test/fixture/pages/ssr.vue b/test/fixture/pages/ssr.vue index 13e822d..9658799 100644 --- a/test/fixture/pages/ssr.vue +++ b/test/fixture/pages/ssr.vue @@ -1,22 +1,28 @@ \ No newline at end of file +