()
| 157 | } |
| 158 | |
| 159 | registerSubrouterMiddleware() { |
| 160 | this.use(async (c, next) => { |
| 161 | const [basePath, routerName] = c.req.path |
| 162 | .split("/") |
| 163 | .filter(Boolean) |
| 164 | .slice(0, 2) |
| 165 | |
| 166 | const key = `/${basePath}/${routerName}` |
| 167 | const subRouter = await this._metadata.subRouters[key] |
| 168 | |
| 169 | if (subRouter) { |
| 170 | const rewrittenPath = "/" + c.req.path.split("/").slice(3).join("/") |
| 171 | const newUrl = new URL(c.req.url) |
| 172 | newUrl.pathname = rewrittenPath |
| 173 | |
| 174 | const newRequest = new Request(newUrl, c.req.raw) |
| 175 | const response = await subRouter.fetch(newRequest, c.env) |
| 176 | |
| 177 | return response |
| 178 | } |
| 179 | |
| 180 | return next() |
| 181 | }) |
| 182 | } |
| 183 | |
| 184 | private setupRoutes(procedures: Record<string, any>) { |
| 185 | Object.entries(procedures).forEach(([key, value]) => { |
no test coverage detected