Skip to content

Commit c84fb56

Browse files
jericopulverapi0
authored andcommitted
fix(defaults): set proper Accept-Encoding for server side (#176)
1 parent e5f132f commit c84fb56

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

Diff for: lib/plugin.template.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,33 @@ const setupProgress = (axios, ctx) => {
148148
}<% } %>
149149

150150
export default (ctx, inject) => {
151-
const axiosOptions = {
152-
// baseURL
153-
baseURL : process.browser
151+
// baseURL
152+
const baseURL = process.browser
154153
? '<%= options.browserBaseURL %>'
155-
: (process.env._AXIOS_BASE_URL_ || '<%= options.baseURL %>'),
156-
157-
// Create fresh objects for all default header scopes
158-
// Axios creates only one which is shared across SSR requests!
159-
// https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
160-
headers: {
161-
common : {
162-
'Accept': 'application/json, text/plain, */*'
163-
},
164-
delete: {},
165-
get: {},
166-
head: {},
167-
post: {},
168-
put: {},
169-
patch: {}
170-
}
154+
: (process.env._AXIOS_BASE_URL_ || '<%= options.baseURL %>')
155+
156+
// Create fresh objects for all default header scopes
157+
// Axios creates only one which is shared across SSR requests!
158+
// https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
159+
const headers = {
160+
common : {
161+
'Accept': 'application/json, text/plain, */*'
162+
},
163+
delete: {},
164+
get: {},
165+
head: {},
166+
post: {},
167+
put: {},
168+
patch: {}
169+
}
170+
171+
if (process.server) {
172+
headers.common['Accept-Encoding'] = 'gzip, deflate'
173+
}
174+
175+
const axiosOptions = {
176+
baseURL,
177+
headers
171178
}
172179

173180
<% if (options.proxyHeaders) { %>

0 commit comments

Comments
 (0)