Skip to content

Add Remix Inspired "Flat Routing" #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

Zurdge
Copy link

@Zurdge Zurdge commented Jul 10, 2024

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
Copy link
Owner

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?

@matthiaaas matthiaaas added the enhancement New feature or request label Jul 16, 2024
@Zurdge
Copy link
Author

Zurdge commented Jul 19, 2024

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. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants