'NestJS controller not mapped
So I have an API that will be deployed in a docker container. This API has the authentications
controller, simple and not something special.
When I start up the API in development mode on my local machine, the auth controller will be found and everything is working fine. Same for building and running it on my local machine. But when I'll dockerize the project and run it on a virtual machine, then I'll can't access the auth controller. Every other controller is working finde, but the auth controller doesn't exist.
Looking into the docker logs, no auth controller will be mapped. Both local and builded docker images should contain the same project files.
auth controller:
import {
Controller,
Post,
Delete,
UseGuards,
Request,
Body,
} from '@nestjs/common';
import { AuthenticationsService } from './authentications.service';
import { JwtAuthGuard } from '../shared/guards/jwtAuth.guard';
import { SignInDTO } from './dtos/addGraphNodeToGraphByGraphId.dto';
@Controller('authentications')
export class AuthenticationsController {
constructor(
private readonly authenticationsService: AuthenticationsService,
) {}
@Post()
public signIn(@Body() { username, password }: SignInDTO): Promise<string> {
return this.authenticationsService.signIn(username, password);
}
@Delete()
@UseGuards(JwtAuthGuard)
public signOut(@Request() request): Promise<void> {
return this.authenticationsService.signOut(
request.encodedToken,
request.user.tokenExpirationSinceEpochInMilliseconds,
);
}
}
Error:
{
"statusCode": 404,
"message": "Not Found",
"error": "Cannot POST /authentications"
}
What could cause that the authentications controller will not be mapped?
Solution 1:[1]
Finally found out that some packages from NestJS had version 6 and 7. So they propably interrupted each other. An indicator was this flood of warnings:
After running nest update -f
every controller was mapped as it was supposed.
Solution 2:[2]
If you have already tried everything else and nothing worked, try deleting the dist
folder. That's what worked for me.
Solution 3:[3]
Did you put the controller in the module?
@Module({
controllers: [AuthenticationController],
})
export class AppModule {}
Solution 4:[4]
I had the same problem as the OP, but it was because I didn't restart my NestJS server after I added that endpoint to the controller.
Also, I'm used to npm start in other contexts auto-updating the server without restart (React, React Native, I think node?).
Solution 5:[5]
did you add it to your app module? The Module of auth.
Solution 6:[6]
I also encountered this problem on the server I deployed yesterday. After a day of research, I was using the master
branch, and my code kept pushing to the dev
branch, so I hope someone can check that as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dewey |
Solution 2 | Utsav Barnwal |
Solution 3 | bashleigh |
Solution 4 | micahhoover |
Solution 5 | erevos13 |
Solution 6 | ??? |