【问题标题】:Math regex express route数学正则表达式快速路线
【发布时间】:2020-06-08 13:10:44
【问题描述】:

我正在尝试使用参数过滤路由,但没有成功。我有 2 条路线:

/all
/:id

我是用typescript-rest动态加载的,所以没办法先添加all路由。

Server.loadServices(this.appWebApi, 'app/resources/*.js', `${__dirname}`);

我有这两种方法:

@GET
@Path("all")
async all(@Context context: ServiceContext) {}

@GET
@Path(":id")
async findById(@Context context: ServiceContext, @PathParam("id") id: string) {}

但是当我使用/all 时,两者都会被调用。我尝试使用^(?!all):id,但参数不起作用。

那么,如何过滤这两条路由呢?

【问题讨论】:

  • 你是按这个顺序放的吗?
  • 是的,因为它不起作用,我试图过滤网址

标签: regex express routes express-router


【解决方案1】:

我找到了解决方案,问题与 typescript-rest 包有关。

这里建议的解决方案:

https://github.com/thiagobustamante/typescript-rest/issues/78#issuecomment-469232775

【讨论】: