matthiaaas / express-file-routing

Flexible file-based routing for Express (like Next.js + additional features)
https://www.npmjs.com/package/express-file-routing
MIT License
83 stars 13 forks source link

Add Remix Inspired "Flat Routing" #36

Open Zurdge opened 2 months ago

Zurdge commented 2 months ago

I would like to structure my API routes in a flat directory, similar to how Remix handles it's routing. https://remix.run/docs/en/main/discussion/routes#conventional-route-configuration

index.ts
blog.:uuid.ts
blog.:uuid.edit.ts

Would it be ok to implement something similar to this? I've tested for my own needs and it works well. Happy to make adjustments 👍

matthiaaas commented 2 months ago

Thank you for the contribution @Zurdge, great idea. I am very curious on whether or not this is something where there is a significant need for.

Maybe a modular approach which lets more space for custom routing strategies makes sense so people can come up with individual file naming conventions. Following a strategy pattern or similar, a significant refactor may be required.

I am imagining an API like:

import { DirectoryStrategy, FlatStrategy } from "express-file-routing"

createRouter(app, {
  strategy: new DirectoryStrategy() // this might be the default directory-file-based strategy like Next.js
}

Therefore, an strategy interface for generating the routes needs to be defined. What do you think?

Zurdge commented 2 months ago

Yeh I think this is a good idea! When I next get time, I'll try and scope out what this enhancement might look like and reply in this thread. 👍