mirror of
https://github.com/coder/code-server.git
synced 2026-04-16 21:31:43 -05:00
Add --abs-proxy-base-path for when code-server is not at the root (#6958)
This commit is contained in:
@@ -53,6 +53,7 @@ export interface UserProvidedCodeArgs {
|
||||
"disable-getting-started-override"?: boolean
|
||||
"disable-proxy"?: boolean
|
||||
"session-socket"?: string
|
||||
"abs-proxy-base-path"?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,6 +280,10 @@ export const options: Options<Required<UserProvidedArgs>> = {
|
||||
short: "w",
|
||||
description: "Text to show on login page",
|
||||
},
|
||||
"abs-proxy-base-path": {
|
||||
type: "string",
|
||||
description: "The base path to prefix to all absproxy requests",
|
||||
},
|
||||
}
|
||||
|
||||
export const optionDescriptions = (opts: Partial<Options<Required<UserProvidedArgs>>> = options): string[] => {
|
||||
|
||||
@@ -121,11 +121,13 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
|
||||
app.router.all("/absproxy/:port/:path(.*)?", async (req, res) => {
|
||||
await pathProxy.proxy(req, res, {
|
||||
passthroughPath: true,
|
||||
proxyBasePath: args["abs-proxy-base-path"],
|
||||
})
|
||||
})
|
||||
app.wsRouter.get("/absproxy/:port/:path(.*)?", async (req) => {
|
||||
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest, {
|
||||
passthroughPath: true,
|
||||
proxyBasePath: args["abs-proxy-base-path"],
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -5,10 +5,15 @@ import { HttpCode, HttpError } from "../../common/http"
|
||||
import { ensureProxyEnabled, authenticated, ensureAuthenticated, ensureOrigin, redirect, self } from "../http"
|
||||
import { proxy as _proxy } from "../proxy"
|
||||
|
||||
const getProxyTarget = (req: Request): string => {
|
||||
const getProxyTarget = (
|
||||
req: Request,
|
||||
opts?: {
|
||||
proxyBasePath?: string
|
||||
},
|
||||
): string => {
|
||||
// If there is a base path, strip it out.
|
||||
const base = (req as any).base || ""
|
||||
return `http://0.0.0.0:${req.params.port}/${req.originalUrl.slice(base.length)}`
|
||||
return `http://0.0.0.0:${req.params.port}${opts?.proxyBasePath || ""}/${req.originalUrl.slice(base.length)}`
|
||||
}
|
||||
|
||||
export async function proxy(
|
||||
@@ -16,6 +21,7 @@ export async function proxy(
|
||||
res: Response,
|
||||
opts?: {
|
||||
passthroughPath?: boolean
|
||||
proxyBasePath?: string
|
||||
},
|
||||
): Promise<void> {
|
||||
ensureProxyEnabled(req)
|
||||
@@ -38,7 +44,7 @@ export async function proxy(
|
||||
|
||||
_proxy.web(req, res, {
|
||||
ignorePath: true,
|
||||
target: getProxyTarget(req),
|
||||
target: getProxyTarget(req, opts),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,6 +52,7 @@ export async function wsProxy(
|
||||
req: pluginapi.WebsocketRequest,
|
||||
opts?: {
|
||||
passthroughPath?: boolean
|
||||
proxyBasePath?: string
|
||||
},
|
||||
): Promise<void> {
|
||||
ensureProxyEnabled(req)
|
||||
@@ -59,6 +66,6 @@ export async function wsProxy(
|
||||
|
||||
_proxy.ws(req, req.ws, req.head, {
|
||||
ignorePath: true,
|
||||
target: getProxyTarget(req),
|
||||
target: getProxyTarget(req, opts),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user