NestJs 中的子路径

Subroute in NestJs

如何使用 Nest 创建子路由?

我正在为 localhost:3000/payment/stripe/get_customer_by_email 尝试类似的东西:

import { Controller, Get } from '@nestjs/common';
import StripeService from './stripe.service';

@Controller('/payments/stripe')
export default class StripeController {
  constructor(private readonly stripeService: StripeService) {}

  @Get('/get_customer_by_email')
  getCustomerByEmail(): string {
    return this.stripeService.getCustomerByEmail();
  }
}

但是当我启动 e2e 测试时出现 404:

    expected 200 "OK", got 404 "Not Found"

      19 |     return request(app.getHttpServer())
      20 |       .get('/payment/stripe/get_customer_by_email')
    > 21 |       .expect(200)
         |        ^
      22 |       .expect('Hello Customer!');
      23 |   });
      24 | });

在您的控制器中,您将 payments/stripe 作为路由,将 GET 作为 get_customer_by_email,但在您的 e2e 中,您正在调用 payment/stripe/get_customer_by_emailpayments vs payment 路线不匹配