fix: create fresh objects for all default header scopes

master
Pooya Parsa 2017-08-13 19:47:02 +04:30
parent 969cdcf664
commit 7ba3ae819d
1 changed files with 18 additions and 3 deletions

View File

@ -114,16 +114,31 @@ const baseURL = process.browser
export default (ctx) => {
const { app, store, req } = ctx
// Create a 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(options.proxyHeaders) { %>
// Default headers
const defaultHeaders = (req && req.headers) ? Object.assign({}, req.headers) : {}
delete defaultHeaders.host
headers.common = (req && req.headers) ? Object.assign({}, req.headers) : {}
delete headers.common.host
<% } %>
// Create new axios instance
const axios = Axios.create({
baseURL,
<% if(options.proxyHeaders) { %>headers: { common: defaultHeaders },<% } %>
headers
})
<% if(options.credentials) { %>