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?
Hint To create a controller using the CLI, simply execute the $ nest g controller cats command. The @Get() HTTP request method decorator before the findAll() method tells Nest to create a handler for a specific endpoint for HTTP requests.
To instruct Nestjs that we need the body values from the request, we should use the @Body() decorator function from the @nestjs/common module before the body parameter. Doing this will bind the body values from the request to the body parameter in the createPost() method.
To get all query parameter values from a GET request, you can use the @Query() decorator function from the @nestjs/common module inside the parameter brackets of the controller's respective method in Nestjs.
To upload a single file, simply tie the FileInterceptor() interceptor to the route handler and extract file from the request using the @UploadedFile() decorator. Hint The FileInterceptor() decorator is exported from the @nestjs/platform-express package. The @UploadedFile() decorator is exported from @nestjs/common .
If you have already tried everything else and nothing worked, try deleting the dist
folder. That's what worked for me.
Did you put the controller in the module?
@Module({
controllers: [AuthenticationController],
})
export class AppModule {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With