nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Possibility to change api and middleware paths

Open n4an opened this issue 1 year ago • 7 comments

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

n4an avatar Oct 03 '22 05:10 n4an

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?

danielroe avatar Oct 03 '22 10:10 danielroe

That also can be configurable with global prefix option https://docs.nestjs.com/faq/global-prefix

n4an avatar Oct 05 '22 05:10 n4an

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

n4an avatar Oct 05 '22 05:10 n4an

You also have the option to use something.get.ts and something.post.ts.

danielroe avatar Oct 05 '22 07:10 danielroe

You also have the option to use something.get.ts and something.post.ts.

I know, but Classes is used in most frameworks, in new frameworks and in other programming languages.

n4an avatar Oct 05 '22 07:10 n4an

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.

danielroe avatar Oct 05 '22 09:10 danielroe

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.

itpropro avatar Oct 15 '22 15:10 itpropro