feat(proxyHeader): proxyHeadersIgnore option

#39
master
Pooya Parsa 2017-09-30 20:02:44 +03:30
parent b1fb704435
commit 7c13655ef4
3 changed files with 9 additions and 3 deletions

View File

@ -43,6 +43,7 @@
- [credentials](#credentials)
- [debug](#debug)
- [proxyHeaders](#proxyheaders)
- [proxyHeadersIgnore](#proxyHeadersIgnore)
- [redirectError](#redirecterror)
- [requestInterceptor](#requestinterceptor)
- [responseInterceptor](#responseinterceptor)
@ -162,6 +163,11 @@ Also helps making consistent requests in both SSR and Client Side code.
> **NOTE:** If directing requests at a url protected by CloudFlare's CDN you should set this to false to prevent CloudFlare from mistakenly detecting a reverse proxy loop and returning a 403 error.
### `proxyHeadersIgnore`
- Default `['host', 'accept']`
Only efficient when `proxyHeaders` is set to true. Removes unwanted request headers to the API backend in SSR.
### `redirectError`
- Default: `{}`

View File

@ -17,6 +17,7 @@ module.exports = function nuxtAxios (moduleOptions) {
browserBaseURL: null,
credentials: true,
proxyHeaders: true,
proxyHeadersIgnore: ['accept', 'host'],
debug: false,
redirectError: {}
}

View File

@ -122,9 +122,8 @@ export default <% if (options.init) { %>async<% } %>(ctx, inject) => {
<% if(options.proxyHeaders) { %>
// Default headers
headers.common = (req && req.headers) ? Object.assign({}, req.headers) : {}
delete headers.common.host
delete headers.common.accept
<% } %>
<% for (let h of options.proxyHeadersIgnore) { %>delete headers.common['<%= h %>']
<% } %><% } %>
// Create new axios instance
const axios = Axios.create({