MCPcopy Index your code
hub / github.com/coder/code-server / proxy

Function proxy

src/node/routes/pathProxy.ts:24–56  ·  view source on GitHub ↗
(
  req: Request,
  res: Response,
  opts?: {
    passthroughPath?: boolean
    proxyBasePath?: string
  },
)

Source from the content-addressed store, hash-verified

22}
23
24export 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
58export async function wsProxy(
59 req: WebsocketRequest,

Callers

nothing calls this directly

Calls 5

ensureProxyEnabledFunction · 0.90
authenticatedFunction · 0.90
selfFunction · 0.90
redirectFunction · 0.90
getProxyTargetFunction · 0.85

Tested by

no test coverage detected