Include query parameters when proxying
This commit is contained in:
parent
561b6343c8
commit
fd339a7433
@ -66,10 +66,12 @@ You can use [Let's Encrypt](https://letsencrypt.org/) to get an SSL certificate
|
|||||||
for free.
|
for free.
|
||||||
|
|
||||||
## How do I access web services?
|
## How do I access web services?
|
||||||
|
|
||||||
code-server is capable of proxying to any port using either a subdomain or a
|
code-server is capable of proxying to any port using either a subdomain or a
|
||||||
subpath.
|
subpath.
|
||||||
|
|
||||||
### Sub-domains
|
### Sub-domains
|
||||||
|
|
||||||
Set up a wildcard certificate for your domain and a wildcard DNS entry (or you
|
Set up a wildcard certificate for your domain and a wildcard DNS entry (or you
|
||||||
can configure each subdomain individually for the ports you expect to use).
|
can configure each subdomain individually for the ports you expect to use).
|
||||||
|
|
||||||
@ -83,6 +85,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?
|
||||||
|
@ -2,6 +2,7 @@ import { logger } from "@coder/logger"
|
|||||||
import * as http from "http"
|
import * as http from "http"
|
||||||
import proxy from "http-proxy"
|
import proxy from "http-proxy"
|
||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
|
import * as querystring from "querystring"
|
||||||
import { HttpCode, HttpError } from "../../common/http"
|
import { HttpCode, HttpError } from "../../common/http"
|
||||||
import { HttpProvider, HttpProviderOptions, HttpProxyProvider, HttpResponse, Route } from "../http"
|
import { HttpProvider, HttpProviderOptions, HttpProxyProvider, HttpResponse, Route } from "../http"
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = this.doProxy(route.requestPath, request, response, base)
|
const payload = this.doProxy(route.requestPath, route.query, request, response, base)
|
||||||
if (payload) {
|
if (payload) {
|
||||||
return payload
|
return payload
|
||||||
}
|
}
|
||||||
@ -62,7 +63,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
head: Buffer,
|
head: Buffer,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this.ensureAuthenticated(request)
|
this.ensureAuthenticated(request)
|
||||||
this.doProxy(route.requestPath, request, socket, head, route.base.replace(/^\//, ""))
|
this.doProxy(route.requestPath, route.query, request, socket, head, route.base.replace(/^\//, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCookieDomain(host: string): string {
|
public getCookieDomain(host: string): string {
|
||||||
@ -83,7 +84,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
response: http.ServerResponse,
|
response: http.ServerResponse,
|
||||||
): HttpResponse | undefined {
|
): HttpResponse | undefined {
|
||||||
const port = this.getPort(request)
|
const port = this.getPort(request)
|
||||||
return port ? this.doProxy(route.fullPath, request, response, port) : undefined
|
return port ? this.doProxy(route.fullPath, route.query, request, response, port) : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
public maybeProxyWebSocket(
|
public maybeProxyWebSocket(
|
||||||
@ -93,7 +94,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
head: Buffer,
|
head: Buffer,
|
||||||
): HttpResponse | undefined {
|
): HttpResponse | undefined {
|
||||||
const port = this.getPort(request)
|
const port = this.getPort(request)
|
||||||
return port ? this.doProxy(route.fullPath, request, socket, head, port) : undefined
|
return port ? this.doProxy(route.fullPath, route.query, request, socket, head, port) : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
private getPort(request: http.IncomingMessage): string | undefined {
|
private getPort(request: http.IncomingMessage): string | undefined {
|
||||||
@ -121,12 +122,14 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
|
|
||||||
private doProxy(
|
private doProxy(
|
||||||
path: string,
|
path: string,
|
||||||
|
query: querystring.ParsedUrlQuery,
|
||||||
request: http.IncomingMessage,
|
request: http.IncomingMessage,
|
||||||
response: http.ServerResponse,
|
response: http.ServerResponse,
|
||||||
portStr: string,
|
portStr: string,
|
||||||
): HttpResponse
|
): HttpResponse
|
||||||
private doProxy(
|
private doProxy(
|
||||||
path: string,
|
path: string,
|
||||||
|
query: querystring.ParsedUrlQuery,
|
||||||
request: http.IncomingMessage,
|
request: http.IncomingMessage,
|
||||||
socket: net.Socket,
|
socket: net.Socket,
|
||||||
head: Buffer,
|
head: Buffer,
|
||||||
@ -134,6 +137,7 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
): HttpResponse
|
): HttpResponse
|
||||||
private doProxy(
|
private doProxy(
|
||||||
path: string,
|
path: string,
|
||||||
|
query: querystring.ParsedUrlQuery,
|
||||||
request: http.IncomingMessage,
|
request: http.IncomingMessage,
|
||||||
responseOrSocket: http.ServerResponse | net.Socket,
|
responseOrSocket: http.ServerResponse | net.Socket,
|
||||||
headOrPortStr: Buffer | string,
|
headOrPortStr: Buffer | string,
|
||||||
@ -159,7 +163,9 @@ export class ProxyHttpProvider extends HttpProvider implements HttpProxyProvider
|
|||||||
autoRewrite: true,
|
autoRewrite: true,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
ignorePath: true,
|
ignorePath: true,
|
||||||
target: `http://127.0.0.1:${port}${path}`,
|
target: `http://127.0.0.1:${port}${path}${
|
||||||
|
Object.keys(query).length > 0 ? `?${querystring.stringify(query)}` : ""
|
||||||
|
}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responseOrSocket instanceof net.Socket) {
|
if (responseOrSocket instanceof net.Socket) {
|
||||||
|
Reference in New Issue
Block a user