nitro
nitro copied to clipboard
Possibility to change api and middleware paths
Environment
Reproduction
handlers Server handlers and routes. If routes/, api/ or middleware/ directories exist, they will be automatically added to the handlers array.
How to modify api and middleware paths?
Describe the bug
Additional context
No response
Logs
No response
Would you explain a bit more about your use case? And if you rename api/
to something-else/
would you still expect that it would be accessed via the /api
prefix when served by nitro?
That also can be configurable with global prefix option https://docs.nestjs.com/faq/global-prefix
And that looks ugly
defineEventHandler((event) => {
if (event.method === 'get') {
} else if (event.method === 'post') {
}
})
but can be like so
@Controller('cats')
export class CatsController {
@Get()
findAll(): string {
return 'This action returns all cats';
}
}
All speak about OOP
You also have the option to use something.get.ts
and something.post.ts
.
You also have the option to use
something.get.ts
andsomething.post.ts
.
I know, but Classes is used in most frameworks, in new frameworks and in other programming languages.
That is not related to this issue, and I do not believe we are likely to implement a pattern with decorators in https://github.com/unjs/h3.
And that looks ugly
defineEventHandler((event) => { if (event.method === 'get') { } else if (event.method === 'post') { } })
but can be like so
@Controller('cats') export class CatsController { @Get() findAll(): string { return 'This action returns all cats'; } }
All speak about OOP
Looks overcomplicated to me, I think using the something.get.ts
and something.post.ts
pattern is fine, didn't have any problems with that in projects so far.
For the initial question, you can just create a folder in the /routes
folder, as the /api
folder is also just a shortcut to /routes/api
.