Skip to content
Permalink
Browse files

fix(defaults): set proper Accept-Encoding for server side (#176)

  • Loading branch information...
jericopulvera authored and pi0 committed Nov 7, 2018
1 parent e5f132f commit c84fb56f20627e048ef88905a7b1875f67d71d2d
Showing with 26 additions and 19 deletions.
  1. +26 −19 lib/plugin.template.js
@@ -148,26 +148,33 @@ const setupProgress = (axios, ctx) => {
}<% } %>

export default (ctx, inject) => {
const axiosOptions = {
// baseURL
baseURL : process.browser
// baseURL
const baseURL = process.browser
? '<%= options.browserBaseURL %>'
: (process.env._AXIOS_BASE_URL_ || '<%= options.baseURL %>'),

// Create fresh objects for all default header scopes
// Axios creates only one which is shared across SSR requests!
// https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
headers: {
common : {
'Accept': 'application/json, text/plain, */*'
},
delete: {},
get: {},
head: {},
post: {},
put: {},
patch: {}
}
: (process.env._AXIOS_BASE_URL_ || '<%= options.baseURL %>')

// Create fresh objects for all default header scopes
// Axios creates only one which is shared across SSR requests!
// https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
const headers = {
common : {
'Accept': 'application/json, text/plain, */*'
},
delete: {},
get: {},
head: {},
post: {},
put: {},
patch: {}
}

if (process.server) {
headers.common['Accept-Encoding'] = 'gzip, deflate'
}

const axiosOptions = {
baseURL,
headers
}

<% if (options.proxyHeaders) { %>

0 comments on commit c84fb56

Please sign in to comment.
You can’t perform that action at this time.