Search code examples
javascriptdockernestjstypeorm

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

  • 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: enter image description here

    After running nest update -f every controller was mapped as it was supposed.

    Edit :

    As of NestJS version 9, the update command has been removed.

    See here : Migration Guide - CLI