标签: nestjs

我们如何指定 opentelemetry 中的迹线数量

我正在使用 opentelemetry 来检测 Nest js 应用程序。假设要发出的请求数量很大。那么我们如何指定要收集的痕迹数量呢?

typescript zipkin nestjs distributed-tracing open-telemetry

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

类型错误:domain.enter 不是函数

描述我试图迁移到的错误Mikro-Orm,我已经被这个错误困扰了超过 3 天,该错误的问题是它不能帮助我知道它来自哪里,问题是它发生在随机区域,我评论了很多代码并试图隔离它的来源,但它是不可预测的。我做了很多研究,我想出了这个https://github.com/mysqljs/mysql/issues/1949https://github.com/sipcentric/node-pbx-client/issues/4,我唯一能想到的就是这mysql就是为什么我猜测 MikroOrm 可能会喜欢它。

任何专家的建议将不胜感激。

问题是我加粗的 Nestjs api 没有响应响应

堆栈跟踪

domain.js:547
  domain.enter();
         ^

TypeError: domain.enter is not a function
    at IncomingMessage.EventEmitter.emit (domain.js:547:10)
    at resume_ (_stream_readable.js:972:10)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Run Code Online (Sandbox Code Playgroud)

重现 我不知道它是如何发生的。

版本 以下是项目的所有依赖项:

 "dependencies": {
    "@angular/animations": "~10.1.4",
    "@angular/cdk": "^10.2.3",
    "@angular/common": "~10.1.4",
    "@angular/compiler": "~10.1.4",
    "@angular/core": "~10.1.4",
    "@angular/forms": "~10.1.4",
    "@angular/localize": "^10.0.4",
    "@angular/material": "^10.2.3",
    "@angular/platform-browser": "~10.1.4",
    "@angular/platform-browser-dynamic": "~10.1.4",
    "@angular/router": "~10.1.4",
    "@fortawesome/angular-fontawesome": "^0.7.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.30",
    "@fortawesome/free-brands-svg-icons": "^5.14.0",
    "@fortawesome/free-regular-svg-icons": "^5.14.0",
    "@fortawesome/free-solid-svg-icons": "^5.14.0",
    "@mikro-orm/core": "^4.3.4",
    "@mikro-orm/mariadb": "^4.3.4", …
Run Code Online (Sandbox Code Playgroud)

node.js nestjs mikro-orm

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

Nestjs Winston 日志文件是用颜色编码编写的

我面临与https://github.com/winstonjs/winston/issues/1416相同的问题,结果logger.info(\'Hello there. How are you?\');\xef\xbf\xbd[32minfo\xef\xbf\xbd[39m: \xef\xbf\xbd[32mHello there. How are you?\xef\xbf\xbd[39m

\n

我不知道在哪里colorize可以删除它,这是我的代码:

\n
  new winston.transports.File({\n    format: winston.format.combine(\n      winston.format.colorize({ // I added this but it\'s still not helping\n        all: false,\n        message: false,\n        level: false,\n      }),\n      winston.format.label({ label: \'API\' }),\n      winston.format.timestamp(),\n      winston.format.printf(({ level, message, label, timestamp }) => {\n        return `${timestamp} [${label}] ${level}: ${message}`;\n      }),\n    ),\n    filename: environment.logDirectory,\n    level: \'http\',\n    maxsize: 1024 * 1024 * 10,\n  }),\n
Run Code Online (Sandbox Code Playgroud)\n

在 中main.ts,我有

\n
import { WINSTON_MODULE_NEST_PROVIDER …
Run Code Online (Sandbox Code Playgroud)

winston nestjs express-winston

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

Nestjs:无法在同一控制器中实现多个 GET 方法

我这里有一些奇怪的问题。我有2种获取方法,一种是通过companyId获取员工列表,一种是通过staffId获取员工详细信息。第二种方法getStaffById不行。如果我注释掉第一个 get 方法getStaffByCompanyId,第二个方法将按预期工作。看起来第一个 get 方法阻止了第二个方法。我在这里错过了什么吗?

@Controller('staff')
@ApiTags('Staff')
export class StaffController {
  constructor(private staffService: StaffService) {}

  @Get(':companyId')
  @ApiResponse({
    status: HttpStatus.OK,
    description: 'Return staffs by id',
  })
  @ApiResponse({
    status: HttpStatus.UNAUTHORIZED,
    description: 'Unauthorized',
    type: Error,
  })
  @ApiResponse({
    status: HttpStatus.UNPROCESSABLE_ENTITY,
    description: 'Get particular staff details',
    type: Error,
  })
  @ApiResponse({
    status: HttpStatus.INTERNAL_SERVER_ERROR,
    description: 'Internal server error',
    type: Error,
  })
  @ApiResponse({
    status: HttpStatus.BAD_GATEWAY,
    description: 'Internal communication error',
    type: Error,
  })
  @ApiOperation({
    operationId: 'getStaffByCompanyId',
    summary: 'Get staff list that attach to the company', …
Run Code Online (Sandbox Code Playgroud)

node.js swagger nestjs

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

覆盖控制器内的 NestJS 路由

我想完全覆盖控制器路线。例如:

@Controller('shipments')
export class ShipmentsController {

  @Post('/create')
  async find(): Promise<Activities> {
    return service.find()
  }
}
Run Code Online (Sandbox Code Playgroud)

为了向前面的示例发出请求,URL 将为:http://localhost:8080/shipments/create

我想更改该 URL,而不将控制器移动到另一个类。例如,我希望该特定函数的 URL 为 http://localhost:8080/whatever/i/want。

这可能吗?

node.js nestjs

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

Nestjs 角色防护调用 2 次并首先获取用户未定义

我使用护照并希望按角色保护几条路线。看起来守卫调用了两次。首先它记录用户未定义。第二次它记录用户正确。我做错了什么?请参阅实施截图。

角色守卫

应用程序模块

用法

node.js nestjs nestjs-passport

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

NestJs:如何将一个存储库导入另一个存储库?

对于这个可能非常业余的问题,我深表歉意。来自 Laravel,这对我来说仍然很困惑,我只是不明白需要什么。

我有一个user.repository.ts文件和一个location.repository.ts文件。每个都有自己的模块、控制器和服务。我已成功为每个实体创建 CRUD 操作,但现在正在尝试建立多对多关系。

在我的user.repository.ts文件中,我尝试保存相关的(多对多)存储库:

// user.repository.ts

user.locations = await this.locationRepository.findByIds(locations);
...

await user.save();
Run Code Online (Sandbox Code Playgroud)

我不确定如何注入或导入location.repository.ts文件。我尝试了多种将服务导入到每个模块的方法。或者将每个模块导入另一个模块中。我尝试过不同的版本:

@EntityRepository(User)
@EntityRepository(Location)
Run Code Online (Sandbox Code Playgroud)

或者将其导入LocationServiceUserService.

在 Laravel 中,这就像“简单”一样$model->sync($relationship);

我如何导入/注入locationRepository到我的userRepository?感谢您的任何建议!

nestjs

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

NestJS + TypeORM 中的 JoinTable 问题

我在 NestJS + TypeORM 中遇到一个奇怪的问题。

我几乎已经在实体中创建了一个 ManyToMany 关系,并且在该关系的拥有方,我添加了不带参数的 @JoinTable() 。

运行 Nest build 后,entity.js 文件添加了一个新的 import const browser_1 = require("typeorm/browser");,我发现它用于在编译的 JS 文件 => 中声明 JoinTable 选项browser_1.JoinTable()

问题是,当使用 typeorm 生成新的迁移文件时,我不断收到以下错误:

import { __awaiter, __generator } from "tslib";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.require.extensions.<computed> [as .js] (C:\XXX\XXX\dev\XXX\pistis-api\node_modules\ts-node\src\index.ts:1045:43)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\XXX\XXX\dev\XXX\pistis-api\dist\modules\collaborator\entity\collaborator.entity.js:17:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30) …
Run Code Online (Sandbox Code Playgroud)

typeorm ts-node nestjs

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

NestJS GraphQL - 我需要创建一个字符串数组字段

我的模型中有这个字段,但不起作用

@Field(type => [],{ nullable: true })
product: string[];
Run Code Online (Sandbox Code Playgroud)

我不知道我想念什么。

graphql nestjs

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

typeorm中的精确一对多是什么

我想确切地知道 Type orm 中的一对多关系是什么

\n
@oneTomany \n
Run Code Online (Sandbox Code Playgroud)\n

这个命令本身是否是一个列并且该列的值保存在另一个表\xd8\x9f\xd8\x9f中

\n

它的具体参数是什么?

\n

typeorm nestjs

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