popomore / koa-proxy

Proxy middleware for koa
223 stars 102 forks source link

Add custom headers #11

Closed kilianc closed 8 years ago

kilianc commented 9 years ago

How do I add an Authorization header to the proxied req ?

popomore commented 9 years ago

PR is welcome.

kilianc commented 9 years ago

this is how I fixed it:

app.use(mount('/es', function *(next) {
  this.header.host = process.env.ES_HOST
  this.header.authorization = 'Basic ' + process.env.ES_AUTH
  yield* next
}))

app.use(mount('/es', proxy({
  host: process.env.ES_PROTOCOL + process.env.ES_HOST
})))

in my case I am proxying to elasticsearch on bonsai.io

I will try to submit a PR but I can't promise to be able to this week.

lizell commented 8 years ago

This PR, #20, allows you to control the options of the proxied request, including headers.