【发布时间】:2021-07-17 23:36:03
【问题描述】:
如何使用 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_customer_by_email'而不是'/payment/stripe/get_customer_by_email'。
标签: javascript typescript backend nestjs