Skip to content

Commit 074f98c

Browse files
author
pooya parsa
committed
feat(plugin): enable server brotli if supported (closes nuxt-community#276)
1 parent 18afe5c commit 074f98c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/plugin.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import defu from 'defu'
44

55
const globalName = '<%= globalName %>'
66

7+
// Check Node.js brotli support
8+
let brotliSupported
9+
if (process.server) {
10+
const zlib = require('zlib')
11+
brotliSupported = typeof zlib.createBrotliDecompress == 'function'
12+
}
13+
714
// Axios.prototype cannot be modified
815
const axiosExtra = {
916
setBaseURL (baseURL) {
@@ -206,8 +213,8 @@ export default (ctx, inject) => {
206213
}
207214
<% } %>
208215

209-
if (process.server) {
210-
// Don't accept brotli encoding because Node can't parse it
216+
// Don't accept brotli encoding because Node can't parse it
217+
if (process.server && !brotliSupported) {
211218
axiosOptions.headers.common['accept-encoding'] = 'gzip, deflate'
212219
}
213220

0 commit comments

Comments
 (0)