ITADN

Is it possible to combine/compose multiple routers?

#134Closedryanto 创建于 2024-03-09
R
ryantocommented
First, thank you so much for hattip, I absolutely love working with it! I'm building a server that needs to combine multiple "apps" into one, and I was hoping I could combine two routers like so: ```js let productRouter = createRouter(); productRouter.get("/a/:product", ...); let widgetRouter = createRouter(); widgetRouter.get("/b/:widget", ...); productRouter.use(widgetRouter.buildHandler()); createServer(productRouter.buildHandler()); ``` This would let me serve both `/a/product` and `/b/widget`. However, I noticed that `productRouter.use(widgetRouter.buildHandler())` causes widgetRouter to call `passThrough()` if it can't respond to the request, so the productRouter's routes never get run. The passThrough causes a 404. Hopefully this question makes sense, but I can provide more details if needed! Thank you again!
关闭于 2024-03-27 4 条评论