【发布时间】:2020-10-08 12:59:23
【问题描述】:
所以我有一个将部署在 docker 容器中的 API。这个 API 有 authentications 控制器,简单而不特别。
当我在本地机器上以开发模式启动 API 时,将找到身份验证控制器并且一切正常。在我的本地机器上构建和运行它也是如此。但是当我将项目 dockerize 并在虚拟机上运行它时,我将无法访问身份验证控制器。其他所有控制器都在工作 finde,但身份验证控制器不存在。
查看 docker 日志,不会映射任何身份验证控制器。本地和构建的 docker 镜像都应该包含相同的项目文件。
身份验证控制器:
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,
);
}
}
错误:
{
"statusCode": 404,
"message": "Not Found",
"error": "Cannot POST /authentications"
}
什么可能导致无法映射身份验证控制器?
【问题讨论】:
-
如果你修改一个现有的控制器,它是否会重新执行 docker 容器中的修改?
-
将需要此控制器的模块代码放入问题中。也许这里有什么东西。另外,您在本地和 docker 中有哪些操作系统?
标签: javascript docker nestjs typeorm