Skip to content

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

@guguji5

Description

@guguji5

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions