faster icon indicating copy to clipboard operation
faster copied to clipboard

FR: add prefix option for .use()

Open Tzahile opened this issue 1 year ago • 2 comments

Hi, Thanks for giving from your time and creating a small, super-fast server library for Deno!

I'd like to ask for a feature;

In express.js (and many others) you can set a prefix for the routes you define, in the following way:

import { usersRoute } from "./users.ts"
import { teamsRoute } from "./teams.ts"
import { v2Route } from "./v2.ts"

const route = new Route()
route.use('/users', usersRoute)
route.use('/teams', teamsRoute)
route.use('/api/v2', v2Route)

route.get(
  '/',
  res('json'),
  req('json'),
  async (ctx: any, next: any) => { ... } // etc
)

The use-case here is to give a prefix to all the routes in usersRoute, teamsRoute.. Then, if in usersRoute I defined the following route:

route.get(
  '/payments',
  res('json'),
  req('json'),
  async (ctx: any, next: any) => { ... } // etc
)

then it will be served in localhost:80/users/payments.

If you prefer me to work on it and create a PR, I'll be happy to. Thanks in advance

Tzahile avatar Oct 18 '23 13:10 Tzahile

Hello, I will work on this feature. It is simple to implement. Will be available soon.

hviana avatar Oct 18 '23 23:10 hviana

I added your feature with native JavaScript resources, see: https://github.com/hviana/faster#organizing-routes-in-files

hviana avatar Dec 11 '23 16:12 hviana