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) - [credentials](#credentials)
- [debug](#debug) - [debug](#debug)
- [proxyHeaders](#proxyheaders) - [proxyHeaders](#proxyheaders)
- [proxyHeadersIgnore](#proxyHeadersIgnore)
- [redirectError](#redirecterror) - [redirectError](#redirecterror)
- [requestInterceptor](#requestinterceptor) - [requestInterceptor](#requestinterceptor)
- [responseInterceptor](#responseinterceptor) - [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. > **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` ### `redirectError`
- Default: `{}` - Default: `{}`

View File

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

View File

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