Skip to content

Commit

Permalink
fix(defaults): set proper Accept-Encoding for server side (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
jericopulvera authored and pi0 committed Nov 7, 2018
1 parent e5f132f commit c84fb56
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions lib/plugin.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) { %>
Expand Down

0 comments on commit c84fb56

Please sign in to comment.