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

koa-proxies should be In front of the koa-bodyparser. #55

Closed
guguji5 opened this issue Jul 18, 2020 · 0 comments · Fixed by #61
Closed

koa-proxies should be In front of the koa-bodyparser. #55

guguji5 opened this issue Jul 18, 2020 · 0 comments · Fixed by #61

Comments

@guguji5
Copy link

guguji5 commented Jul 18, 2020

I test koa proxies in my project, I find a weird bug when it works with koa-bodyparser.

// this works well.
const Koa = require('koa');
const app = new Koa();
const proxy = require('koa-proxies')
const bodyParser = require('koa-bodyparser');

app.use(proxy('/user', {
  target: 'http://example.com',    
  changeOrigin: true,
  rewrite: path => path
}))
app.use(bodyParser())
app.listen(8080);
// this works with bug "socket hang up".
const Koa = require('koa');
const app = new Koa();
const proxy = require('koa-proxies')
const bodyParser = require('koa-bodyparser');
app.use(bodyParser())

app.use(proxy('/user', {
  target: 'http://example.com',    
  changeOrigin: true,
  rewrite: path => path
}))

app.listen(8080);

the only difference is the sequence of the bodyParser and proxy.
I guess the post data will be consumed by the bodyParser, that is not what we want and will not proxy to our target, so it should be placed behind the proxy.

It will save our time if document it. Thank you.

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

Successfully merging a pull request may close this issue.

1 participant