mirror of https://github.com/sundowndev/http.git
fix: create fresh objects for all default header scopes
parent
969cdcf664
commit
7ba3ae819d
|
@ -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) { %>
|
||||
|
|
Loading…
Reference in New Issue