nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Docs: explain index files for server routing

Open geromegrignon opened this issue 1 year ago • 4 comments

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

  • [X] Would you be willing to help implement this feature?

geromegrignon avatar May 05 '24 18:05 geromegrignon

PR more than welcome to improve nitro docs 🙏🏼

pi0 avatar May 07 '24 12:05 pi0

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

geromegrignon avatar May 07 '24 12:05 geromegrignon

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

ilyafish avatar Jun 27 '24 00:06 ilyafish

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

geromegrignon avatar Jun 27 '24 09:06 geromegrignon