Andurit
Andurit

Reputation: 5762

NestJS - Route with ID returns 404

I'm new in NestJS so I obviously do something wrong but can't figurate out what it is.

Problem:

I've got route with ID and text right after it (`/:id/video`), when ever I try to make HTTP request on it I get 404 response.

In same controller I've got route without text after it (/:id) which works totally fine.

Code:

My whole controller looks like code below. Just reminding controller is correctly used in module and so on because other endpoints works fine.
@Controller('channel')
export class ChannelController extends CrudController<Channel> {

constructor(
    private readonly channelService: ChannelService,
    private readonly videoService: VideoService
) {
    super(channelService);
}

@Get()    
async findAll(@Query() params): Promise<Pagination<Channel>> {
    return this.channelService.findAll({take: params.take, skip: params.skip, relations: ['language']});
}

@Get('/:id')
async findOne(@Param('id') id) {
    return this.channelService.findOne({relations: ['language']});
}

@Get('/:id/video')
async findVideosByChannelId(@Param('id') id) {
    return this.channelService.findOne({relations: ['language']});        
}

}

Error:

{"statusCode":404,"message":"Cannot GET /channel/3/video","error":"Not Found"}

Guys and idea or hint what I'm doing wrong is welcome.

Upvotes: 0

Views: 2823

Answers (1)

Juan Rambal
Juan Rambal

Reputation: 629

Just like MorKadosh said, remove the slash because NestJS adds the first slash by default if you dont remove it your final endpoint will be somenthing like this:

http://localhost:3000/channel//:id

Upvotes: 2

Related Questions