koa2-proxy-middleware icon indicating copy to clipboard operation
koa2-proxy-middleware copied to clipboard

Usage with middlewares

Open karladler opened this issue 5 years ago • 1 comments

Is it possible to use this together with middlewares? I would like to check and modify some headers in the corresponding middleware.

karladler avatar Nov 27 '18 13:11 karladler

@abimelex

  • If you want to do something at request header or response header, you can use option. The usage is the same as http-proxy-middleware is. example:
options = {
  targets: {
    '/user': {
      // this is option of http-proxy-middleware
      target: 'http://localhost:3001', // target host
      changeOrigin: true, // needed for virtual hosted sites
      onProxyRes: (proxyRes, req, res) => {
        proxyRes.headers['x-added'] = 'foobar' // add new header to response
      }
    }
  }
}

options look at http-proxy-middleware options

  • Is it possible use this middleware with other? yes, it is. If you want to check something,just write a middleware and put it in front of koa2-proxy-middleware...

sunyongjian avatar Nov 28 '18 03:11 sunyongjian