小编Paw*_*wel的帖子

Mailgun - 401 禁止

我尝试使用 mailgun 发送电子邮件。我使用 node.js (nest.js),这是我的邮件服务。我应该改变什么?当我尝试发送第一封电子邮件(mailgun 官方网站中的描述)时,我收到了相同的错误消息。

import { Injectable } from '@nestjs/common';
import * as Mailgun from 'mailgun-js';
import { IMailGunData } from './interfaces/mail.interface';
import { ConfigService } from '../config/config.service';

@Injectable()
export class MailService {
  private mg: Mailgun.Mailgun;

  constructor(private readonly configService: ConfigService) {
    this.mg = Mailgun({
      apiKey: this.configService.get('MAILGUN_API_KEY'),
      domain: this.configService.get('MAILGUN_API_DOMAIN'),
    });
  }

  send(data: IMailGunData): Promise<Mailgun.messages.SendResponse> {
    console.log(data);
    console.log(this.mg);
    return new Promise((res, rej) => {
      this.mg.messages().send(data, function (error, body) {
        if (error) {
          console.log(error);
          rej(error);
        }
        res(body);
      });
    });
  }
} …
Run Code Online (Sandbox Code Playgroud)

httpforbiddenhandler node.js mailgun nestjs

8
推荐指数
3
解决办法
3350
查看次数

Git bash 无法运行任何 ng 命令(Angular CLI)

我正在研究 git bash cmd。当我尝试运行ng命令时,例如ng serve或ng gc new-component我看到这个输出:

C:\Users\user\AppData\Roaming\npm/node_modules/node/bin/node: line 1: this: command not found

在输出中间,我看到左右斜线有问题。我该如何解决?

我想,环境路径没有问题,因为所有 ng 命令都在 Windows cmd 或 PowerShell 中工作。

bash git-bash angular-cli

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

如何将 Java 记录用作 ModelMapper 的 DTO?

我正在重构我的代码。我想在我的 DTO 中使用 java 记录而不是 java 类。要将 DTO 转换为实体,我使用的是 ModelMapper(2.3.5 版)。当我尝试获取有关用户的信息(调用方法将实体转换为 DTO)时,出现此错误。

Failed to instantiate instance of destination xxx.UserDto. Ensure that xxx.UserDto has a non-private no-argument constructor.

这是我的代码。

public record UserDto(String firstName,
                      String lastName,
                      String email,
                      String imageUrl) {}

Run Code Online (Sandbox Code Playgroud)
@RestController
public class UserController {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private ModelMapper modelMapper;


    @GetMapping("/user/me")
    @PreAuthorize("hasRole('USER')")
    public UserDto getCurrentUser(@CurrentUser UserPrincipal userPrincipal) {
        return convertToDto(userRepository.findById(userPrincipal.getId())
                .orElseThrow(() -> new ResourceNotFoundException("User", "id", userPrincipal.getId())));
    }


    private UserDto convertToDto(User user) {
        UserDto userDto = modelMapper.map(user, UserDto.class);
        return …
Run Code Online (Sandbox Code Playgroud)

java modelmapper java-14 java-record

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