gpt4 book ai didi

fastify - Fastify 中同一处理程序的多个路径

转载 作者:行者123 更新时间:2023-12-02 02:51:13 24 4
gpt4 key购买 nike

在 fastify 中,有没有办法为路由/路径添加别名?基本上,以相同的方式处理两条路径。这对于迁移 API 很有用。

我知道我可以将处理程序函数抽象为一个命名函数,并将该函数传递给两个路由。我只是想知道是否还有其他方法可以做到这一点?

最佳答案

不,没有将一组路由设置到一个处理程序的功能 (here the registration logic if you would like to add this feature)。

我建议像这样注册路由:

['/', '/alias'].forEach(path => {
fastify.route({
method: ['GET'], // you could define multiple methods
url: path,
handler: mySharedHandler
})
})

关于fastify - Fastify 中同一处理程序的多个路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61946959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com