小编Éme*_*nto的帖子

如果我在 swarm 中使用 .env 文件,则未为 mariadb 容器设置 MYSQL_ROOT_PASSWORD 环境变量

当我尝试使用 docker swarm 设置集群时,我收到此错误:

$ docker logs 6ea0f7290cb0  
2020-11-30 10:46:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.8+maria~focal started.
2020-11-30 10:46:08+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-11-30 10:46:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.8+maria~focal started.
2020-11-30 10:46:08+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
        You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
Run Code Online (Sandbox Code Playgroud)

有什么奇怪的,因为如果我使用 docker-compose 工具,一切都运行良好。

要复制此问题,请按照以下步骤操作。

创建一个.env文件:

DB_NAME=nest
DB_USERNAME=nest
DB_PASSWORD=nest
DB_ROOT_PASSWORD=nest
Run Code Online (Sandbox Code Playgroud)

创建一个docker-compose.yml文件:

version: '3.8'

services:

  db: …
Run Code Online (Sandbox Code Playgroud)

mysql mariadb docker docker-compose docker-swarm

5
推荐指数
1
解决办法
7312
查看次数

如何使用 NestJS 和 Passport 设置自定义未经授权的 oauth2 错误

我正在使用自定义护照策略,如果客户端拒绝访问 oauth2 应用程序,我想向客户端发送自定义错误。

这是授权流程:

在此输入图像描述

我想向用户发送自定义错误消息而不是 500 错误。如果成功,当用户授权应用程序时一切都会顺利。

在 NestJS 官方文档中,有一个示例说明了如何执行此操作: https://docs.nestjs.com/security/authentication#extending-guards

import {
  ExecutionContext,
  Injectable,
  UnauthorizedException,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  canActivate(context: ExecutionContext) {
    // Add your custom authentication logic here
    // for example, call super.logIn(request) to establish a session.
    return super.canActivate(context);
  }

  handleRequest(err, user, info) {
    // You can throw an exception based on either "info" or "err" arguments
    if (err || !user) {
      throw err || new …
Run Code Online (Sandbox Code Playgroud)

exception oauth-2.0 passport.js nestjs

5
推荐指数
0
解决办法
2063
查看次数