diff --git a/lib/plugin.js b/lib/plugin.js index a7fcc0f..3cbfc6c 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -4,6 +4,13 @@ import defu from 'defu' const globalName = '<%= globalName %>' +// Check Node.js brotli support +let brotliSupported +if (process.server) { + const zlib = require('zlib') + brotliSupported = typeof zlib.createBrotliDecompress == 'function' +} + // Axios.prototype cannot be modified const axiosExtra = { setBaseURL (baseURL) { @@ -206,8 +213,8 @@ export default (ctx, inject) => { } <% } %> - if (process.server) { - // Don't accept brotli encoding because Node can't parse it + // Don't accept brotli encoding because Node can't parse it + if (process.server && !brotliSupported) { axiosOptions.headers.common['accept-encoding'] = 'gzip, deflate' }