mirror of https://git.tuxpa.in/a/code-server.git
Ensure a trailing slash on subpath proxy
This commit is contained in:
parent
e68d72c4d6
commit
561b6343c8
|
@ -83,7 +83,7 @@ Now you can browse to `<port>.coder.com`. Note that this uses the host header so
|
||||||
ensure your reverse proxy forwards that information if you are using one.
|
ensure your reverse proxy forwards that information if you are using one.
|
||||||
|
|
||||||
### Sub-paths
|
### Sub-paths
|
||||||
Just browse to `/proxy/<port>`.
|
Just browse to `/proxy/<port>/`.
|
||||||
|
|
||||||
## x86 releases?
|
## x86 releases?
|
||||||
|
|
||||||
|
|
|
@ -30,15 +30,24 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
||||||
request: http.IncomingMessage,
|
request: http.IncomingMessage,
|
||||||
response: http.ServerResponse,
|
response: http.ServerResponse,
|
||||||
): Promise<HttpResponse> {
|
): Promise<HttpResponse> {
|
||||||
|
const isRoot = !route.requestPath || route.requestPath === "/index.html"
|
||||||
if (!this.authenticated(request)) {
|
if (!this.authenticated(request)) {
|
||||||
// Only redirect from the root. Other requests get an unauthorized error.
|
// Only redirect from the root. Other requests get an unauthorized error.
|
||||||
if (route.requestPath && route.requestPath !== "/index.html") {
|
if (isRoot) {
|
||||||
throw new HttpError("Unauthorized", HttpCode.Unauthorized)
|
return { redirect: "/login", query: { to: route.fullPath } }
|
||||||
}
|
}
|
||||||
return { redirect: "/login", query: { to: route.fullPath } }
|
throw new HttpError("Unauthorized", HttpCode.Unauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = this.doProxy(route.requestPath, request, response, route.base.replace(/^\//, ""))
|
// Ensure there is a trailing slash so relative paths work correctly.
|
||||||
|
const base = route.base.replace(/^\//, "")
|
||||||
|
if (isRoot && !route.originalPath.endsWith("/")) {
|
||||||
|
return {
|
||||||
|
redirect: `/proxy/${base}/`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = this.doProxy(route.requestPath, request, response, base)
|
||||||
if (payload) {
|
if (payload) {
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue