sdd / koa2-pixie-proxy

A proxy module for koa.js
3 stars 0 forks source link

Getting NOT FOUND on a single route proxy #5

Closed supasympa closed 7 years ago

supasympa commented 7 years ago

It doesn't seem to work with my installation of Koa2

const PORT = process.env.PORT || 3000
const ROOT_DIR = './day1-client/build'

const Koa = require('koa')
const app = new Koa()

const Router = require('koa-router')
const router = Router()
const body = require('koa-body')

const pixie = require('koa2-pixie-proxy')
const proxy = pixie({host: 'http://localhost:2001'})

app.use(require('koa-static')(ROOT_DIR))
app.use(body())

router.get('/reply', proxy('/reply'))
router.post('/reply', proxy('/reply'))

app
  .use(router.middleware())

app.listen(PORT)
console.log('lisetning on port ', PORT)

Calling http://localhost:3000 returns NOT FOUND I can open http://localhost:2001 directly and it works as expected.

sdd commented 7 years ago

What about calling http://localhost:3000/reply ? http://localhost:3000 (ie the root) is itself not proxied, only /reply

sdd commented 7 years ago

I've just created a new project, and ran yarn add koa@2 koa-router@next koa-body@next koa2-pixie-proxy. Then I pasted the content of your code above into an index.js file, and added the following at the bottom, in order to simulate your proxied server on port 2001:

const otherApp = new Koa();
otherApp.use(ctx => ctx.body = 'OK!');
otherApp.listen(2001);

If I execute the file and browse to http://localhost:2001 i see 'OK!'. I get the same if I browse to http://localhost:3000/reply.

If you want the http://localhost:3000 url to return something other than a 404, you need to either add some middleware to the Koa instance on port 3000 that will serve content, or proxy the root route as well as /reply.

supasympa commented 7 years ago

Thanks @sc0ttyd. Sorry if I wasted any of your time I must have messed up.

sdd commented 7 years ago

Hey, no problem, glad I could help!

On 27 Feb 2017 20:56, "Lewis Barclay" notifications@github.com wrote:

Thanks @sc0ttyd https://github.com/sc0ttyd. Sorry if I wasted any of your time I must have messed up.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sc0ttyd/koa2-pixie-proxy/issues/5#issuecomment-282850717, or mute the thread https://github.com/notifications/unsubscribe-auth/AATvb2FEJwnzB8XvRCUZ5Yv2THOEmoVJks5rgziYgaJpZM4MGGaR .