unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.48k stars 472 forks source link

Docs: explain index files for server routing #2415

Open geromegrignon opened 2 months ago

geromegrignon commented 2 months ago

Describe the feature

The server routes documentation is missing a basic folder structure scenario, implying you are familiar with file-based routing structure.

It doesn't explain you can prefix files with index, like index.get.ts.

It unlocks using a folder for crud operations like:

articles
  - index.get.ts
  - index.post.ts
  - index.delete.ts

Or being able to cover routes like /articles and /articles/upcoming.

articles
  index.get.ts
  upcoming
    index.get.ts

Additional information

pi0 commented 1 month ago

PR more than welcome to improve nitro docs 🙏🏼

geromegrignon commented 1 month ago

Awesome I wanted to wait for feedback from the team before starting working on it. I'll land a PR!

ilyafish commented 1 week ago

@geromegrignon please a PR would be huge for this!

Using your example, I had my routes configured like this:

src/api/v1
  - articles.get.ts
  - articles.post.ts
  - articles.delete.ts
src/api/v1/articles
  - upcoming.get.ts
  - upcoming.post.ts

It drove me crazy because I couldn't find any examples of doing this any other way while having a feeling it was possible and I was missing something. I only found this because my OCD finally had enough and I decided to spend an hour going through nearly every issue until I came across this.

geromegrignon commented 1 week ago

Hi @ilyafish, sure I'll work on it tomorrow! Glad it already helped!