popomore / koa-proxy

Proxy middleware for koa
223 stars 102 forks source link

How to proxy app.get() in Koa v2? #32

Closed 0x80 closed 8 years ago

0x80 commented 8 years ago

I am trying to use koa-proxy with koa v2. The

app.use(convert(proxy({host: ..., match: ...})) works fine

Now I want to map one url to a specific proxy url. The docs talk about app.get() but since Koa 2 doesn't have an app.get() function anymore I figured I have to use koa-router...

Using koa-router@next, I've tried this:

router.get('/one', proxy({
   host: 'http://localhost:7777',
   map: function(path) { return '/something/' + path }
}))

router.get('/two', proxy({url: 'http://localhost:7777'}))

app
  .use(router.routes())
  .use(router.allowedMethods())

Calling /one or /two is logged in my Koa server but nothing is passed to the proxy. What am I missing?

0x80 commented 8 years ago

Ah damn it. I forgot to put a convert() around the proxy call.