| 6 | import type { WebsocketRequest } from "../wsRouter" |
| 7 | |
| 8 | const getProxyTarget = ( |
| 9 | req: Request, |
| 10 | opts?: { |
| 11 | proxyBasePath?: string |
| 12 | }, |
| 13 | ): string => { |
| 14 | // If there is a base path, strip it out. |
| 15 | const base = (req as any).base || "" |
| 16 | // Cast since we only have one port param. |
| 17 | const port = parseInt(req.params.port as string, 10) |
| 18 | if (isNaN(port)) { |
| 19 | throw new HttpError("Invalid port", HttpCode.BadRequest) |
| 20 | } |
| 21 | return `http://0.0.0.0:${port}${opts?.proxyBasePath || ""}/${req.originalUrl.slice(base.length)}` |
| 22 | } |
| 23 | |
| 24 | export async function proxy( |
| 25 | req: Request, |