ZijianHe / koa-router

Router middleware for koa.
MIT License
4.85k stars 407 forks source link

`prefix` seems to be broken #496

Closed batrudinych closed 5 years ago

batrudinych commented 5 years ago

node.js version: 10.15.1 npm version: 6.4.1 koa-router version: 7.4.0 koa version: 2.7.0

Code sample:

const Koa = require('koa')
const app = new Koa()
const Router = require('koa-router')

const ordersRouter = new Router({ prefix: 'orders' })

ordersRouter.get('/', ctx => {
  ctx.body = 'Orders'
})

app
  .use(ordersRouter.routes())

app.listen(3000)

Expected Behavior:

localhost:3000/orders responds with Orders string

Actual Behavior:

localhost:3000/orders responds with 404 Not Found

ralyodio commented 5 years ago

This looks correct to me.

batrudinych commented 5 years ago

@chovy does this work as expected on your machine? With certain versions in use

bytesnz commented 5 years ago

Are you just missing a / at the start of the prefix?

5c5
< const ordersRouter = new Router({ prefix: 'orders' })
---
> const ordersRouter = new Router({ prefix: '/orders' })
batrudinych commented 5 years ago

Thanks @bytesnz Awkward situation :) My bad

bytesnz commented 5 years ago

No problem. Glad that was it. Been there, done that. :smile: