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

x-www-form-urlencoded #43

Closed
stigmat4j opened this issue Dec 22, 2015 · 8 comments
Closed

x-www-form-urlencoded #43

stigmat4j opened this issue Dec 22, 2015 · 8 comments
Labels

Comments

@stigmat4j
Copy link

Hi.
Header 'Content-Type: application/x-www-form-urlencoded'
Not working...
Error:
[HPM] Proxy error: ECONNRESET. localhost -> "api.*.com/oauth/token"

@chimurai
Copy link
Owner

Please provide more information:
https://github.com/chimurai/http-proxy-middleware/blob/master/CONTRIBUTING.md

Can you provide a minimal working example, if you think it is a bug?

@stigmat4j
Copy link
Author

My request

export function fetchToken(data) {
  let body = {
    username: data.email,
    password: data.password,
  };
  return fetch(`/oauth/token`, {
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    body: JSON.stringify(body)
  })
  .then((r) => r.json());
}

My server.js

const proxy = proxyMiddleware(['/api', '/oauth'], {
  target: 'http://api.tradeintel.com/',
  xfwd: true   (meybe???)
});

app.use(proxy);

Other requests with 'Content-Type: application\json' is good working.

P.S. Sorry for my English.

@chimurai
Copy link
Owner

Don't see a weird config..

Did you try the changeOrigin option?
Assuming your target server is an vhost server. (shared ip)

const proxy = proxyMiddleware(['/api', '/oauth'], {
  target: 'http://api.tradeintel.com/',
  changeOrigin: true
});

@stigmat4j
Copy link
Author

No, changeOrigin did not help
Alt text

@chimurai
Copy link
Owner

Try checking this thread: #40 (comment)

If you are using multiple middlewares, make sure http-proxy-middleware is on top.
The order is might matter.

@stigmat4j
Copy link
Author

Yeah!
I'm commented

// app.use(parser.json());
// app.use(parser.urlencoded({ extended: true }));

It works :)
Thx!

@chimurai
Copy link
Owner

Np!

@exalted
Copy link

exalted commented Apr 7, 2022

@chimurai After all these years, this issue has cost me quite some time. I think it's worthwhile adding a mention about other default/built-in middleware possibly messing with this one. I understand not everyone uses Express, yet I bet many do, so a few lines in the README would save a bunch of time for many folks and improve the UX overall, I think. ✌️

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

No branches or pull requests

3 participants