(
req: Request,
res: Response,
opts?: {
passthroughPath?: boolean
proxyBasePath?: string
},
)
| 22 | } |
| 23 | |
| 24 | export async function proxy( |
| 25 | req: Request, |
| 26 | res: Response, |
| 27 | opts?: { |
| 28 | passthroughPath?: boolean |
| 29 | proxyBasePath?: string |
| 30 | }, |
| 31 | ): Promise<void> { |
| 32 | ensureProxyEnabled(req) |
| 33 | |
| 34 | if (req.method === "OPTIONS" && req.args["skip-auth-preflight"]) { |
| 35 | // Allow preflight requests with `skip-auth-preflight` flag |
| 36 | } else if (!(await authenticated(req))) { |
| 37 | // If visiting the root (/:port only) redirect to the login page. |
| 38 | if (!req.params.path || req.params.path === "/") { |
| 39 | const to = self(req) |
| 40 | return redirect(req, res, "login", { |
| 41 | to: to !== "/" ? to : undefined, |
| 42 | }) |
| 43 | } |
| 44 | throw new HttpError("Unauthorized", HttpCode.Unauthorized) |
| 45 | } |
| 46 | |
| 47 | // The base is used for rewriting (redirects, target). |
| 48 | if (!opts?.passthroughPath) { |
| 49 | ;(req as any).base = req.path.split(path.sep).slice(0, 3).join(path.sep) |
| 50 | } |
| 51 | |
| 52 | _proxy.web(req, res, { |
| 53 | ignorePath: true, |
| 54 | target: getProxyTarget(req, opts), |
| 55 | }) |
| 56 | } |
| 57 | |
| 58 | export async function wsProxy( |
| 59 | req: WebsocketRequest, |
nothing calls this directly
no test coverage detected