midway icon indicating copy to clipboard operation
midway copied to clipboard

定义路由的方式

Open yuu2lee4 opened this issue 5 years ago • 9 comments

现在有这么一个需求,我的路由根据提供方式有很多种类型,有对内的,有给前端的,有的是openapi,我再controller下面建立了三个文件夹,inward、zuul、open,希望inward下面的路由前面统一有个/inward的前缀,以此类推,目前就只能在每个controller文件里手写前缀,很不优雅,希望就是按照文件夹自动加上前缀或者说能通过某种方式自己定义

yuu2lee4 avatar May 21 '19 09:05 yuu2lee4

所以说你的 controller/inward 文件夹下有很多 controller 文件?

czy88840616 avatar May 21 '19 09:05 czy88840616

所以说你的 controller/inward 文件夹下有很多 controller 文件?

我的理解,应该是自动带上目录,作为url路径的prefix

kurten avatar May 21 '19 09:05 kurten

@kurten 不好吧,这样就和目录有关系了,到时候拆文件出来就有影响了。

czy88840616 avatar May 21 '19 09:05 czy88840616

可以写个 util 根据 __dirname 在每个文件开头算一个前缀

Lellansin avatar May 21 '19 09:05 Lellansin

不知道业界是怎么弄得,反正现在这种是很麻烦

yuu2lee4 avatar May 21 '19 12:05 yuu2lee4

加个中间层进行路由分发

zhou-z-xin avatar Aug 01 '19 03:08 zhou-z-xin

有好的解决方法了吗

a1235 avatar Aug 31 '21 16:08 a1235

所以说你的 controller/inward 文件夹下有很多 controller 文件?

我的理解,应该是自动带上目录,作为url路径的prefix

如果实现了这个需求,那么接下来的自动路由需求将会是 /目录名/文件名(不包含扩展名) 哈哈

waitingsong avatar Sep 01 '21 02:09 waitingsong

这就越来越。。后面应该会提供动态注册路由的 API,比如 app.registerRouter(UserController, { group: 'xxx', prefix: '/v1'}); 这样,不过头疼的就是 swagger 那边怎么取。

动态的话,业务也可以把路由抽象成组件,自己做分组,相对自由很多了,这样甚至单独提供一个基于文件的路由组件都可以了。

czy88840616 avatar Sep 01 '21 02:09 czy88840616

已经提供了动态增加路由的 API。

czy88840616 avatar Sep 14 '22 12:09 czy88840616

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Aug 21 '23 09:08 github-actions[bot]