Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward all headers (missing http-x-requested-with Headers) #130

Closed
LeonardoGentile opened this issue Nov 29, 2016 · 3 comments
Closed

Forward all headers (missing http-x-requested-with Headers) #130

LeonardoGentile opened this issue Nov 29, 2016 · 3 comments

Comments

@LeonardoGentile
Copy link

Expected behavior

I'm using the proxy options in webpack configuration.
My webpack dev server is running at localhost:8888 and my backend is at localhost:8000.
What I was expecting is that all the HTTP HEADERS sent to the webpack dev server would have been forwarded to the proxy server at localhost:8000

Actual behavior

Actually some HTTP HEADERS are missing, at least the one I am interested in, that is: http-x-requested-with XMLHttpRequest. This header is never sent to the destination server and I'm wondering if it is by design or a bug.
The only way to make this work is to manually add this header in the proxy section of the webpack config headers: {'http-x-requested-with' : 'XMLHttpRequest' }

Setup

proxy middleware configuration

  proxy: {
      '/api/*': {
        target: 'http://localhost:8000',
        pathRewrite: {'^/api' : ''},
        secure: false,
        changeOrigin: true,
        headers: {
          'http-x-requested-with' : 'XMLHttpRequest'
        }
      }
    }

server mounting

Webpack devserver config

devServer: {
    contentBase: "./public",
    // do not print bundle build stats
    noInfo: true,
    // enable HMR
    hot: true,
    // embed the webpack-dev-server runtime into the bundle
    inline: true,
    // serve index.html in place of 404 responses to allow HTML5 history
    historyApiFallback: true,
    port: PORT,
    host: HOST,
    proxy: {
      '/api/*': {
        target: 'http://localhost:8000',
        pathRewrite: {'^/api' : ''},
        secure: false,
        changeOrigin: true,
        // manually adding this will add the header back and send it to the destination server
        // headers: {'http-x-requested-with' : 'XMLHttpRequest' }
      }
    }
  },
@LeonardoGentile
Copy link
Author

As side note, with the same configuration when the destination server sends back a response 302 -> the proxy send back to the client a 404 error!! What am I doing wrong?

@LeonardoGentile
Copy link
Author

Probably related to #127

@LeonardoGentile
Copy link
Author

Sorry, my mistake, I was not sending the 'x-requested-with' : 'XMLHttpRequest' in the first place, I was expecting Axios to do this automatically but I was wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant