18

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?

2
  • 2
    If you modify an existing controller, does it repercutes the modification in the docker container ? Commented Jun 24, 2020 at 7:38
  • 2
    Put code of module which requires this controller into the question. Maybe there is something here. Also which operation systems do you have locally and in docker? Commented Jun 25, 2020 at 13:57

8 Answers 8

35

If you have already tried everything else and nothing worked, try deleting the dist folder. That's what worked for me.

Sign up to request clarification or add additional context in comments.

3 Comments

I already found a solution: stackoverflow.com/a/62591471/8408576
The selected answer didn't work for me so, I shared mine just in case anybody else is facing the same thing.
turnout my build was not compiling so intellij was just using the last working version :facepalm: thanks!
7

Did you put the controller in the module?

@Module({
  controllers: [AuthenticationController],
})
export class AppModule {}

1 Comment

Yes, I guess if I wouldn't have done that it would also not work on my local machine
5

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

Comments

2

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?).

Comments

0

did you add it to your app module? The Module of auth.

Comments

0

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.

Comments

0

You can also confirm for typo you're missing the @ for @Module() in any of the affected modules usually the app.module.ts

Comments

0

My issue was not correct log level. Routes mapped incorrectly (wrong path), and log level (use pino) was not debug, so i thought, that routes did not mapped at all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.