Skip to content

Commit

Permalink
feat(plugin): enable server brotli if supported (closes #276)
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Apr 21, 2020
1 parent 18afe5c commit 074f98c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'
}

Expand Down

0 comments on commit 074f98c

Please sign in to comment.