steambap / koa-tree-router

high performance router for Koa
MIT License
138 stars 11 forks source link

feature request - add `prefix` option to Router constructor #2

Closed saadq closed 6 years ago

saadq commented 6 years ago

One thing I miss from koa-router is being able to prefix all your routes.

For example:

import Router from 'koa-router'
const router = new Router()

router.get('/api/cars', async ctx => {

})

router.get('/api/bikes', async ctx => {

})

could be simplified to this:

import Router from 'koa-router'
const router = new Router({ prefix: '/api' })

router.get('/cars', async ctx => {

})

router.get('/bikes', async ctx => {

})

This was quite useful when using a webpack dev server where I would proxy all routes starting with /api to my Node server.