Skip to content

Commit

Permalink
fix: create fresh objects for all default header scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Aug 13, 2017
1 parent 969cdcf commit 7ba3ae8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/plugin.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) { %>
Expand Down

0 comments on commit 7ba3ae8

Please sign in to comment.