diff --git a/lib/plugin.template.js b/lib/plugin.template.js index 6c6d5eb..4dc46d6 100755 --- a/lib/plugin.template.js +++ b/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) { %>