Skip to content

Commit 7c2ca7d

Browse files
committed
Add the ability to prepend to the proxy path
This is for applications like Jupyter that aren't base path agnostic.
1 parent c67d315 commit 7c2ca7d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/node/app/proxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class ProxyHttpProvider extends HttpProvider {
2424
const port = route.base.replace(/^\//, "")
2525
return {
2626
proxy: {
27-
base: `${route.providerBase}/${port}`,
27+
strip: `${route.providerBase}/${port}`,
2828
port,
2929
},
3030
}
@@ -35,7 +35,7 @@ export class ProxyHttpProvider extends HttpProvider {
3535
const port = route.base.replace(/^\//, "")
3636
return {
3737
proxy: {
38-
base: `${route.providerBase}/${port}`,
38+
strip: `${route.providerBase}/${port}`,
3939
port,
4040
},
4141
}

src/node/http.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ export type Query = { [key: string]: string | string[] | undefined }
3636

3737
export interface ProxyOptions {
3838
/**
39-
* A base path to strip from from the request before proxying if necessary.
39+
* A path to strip from from the beginning of the request before proxying
4040
*/
41-
base?: string
41+
strip?: string
42+
/**
43+
* A path to add to the beginning of the request before proxying.
44+
*/
45+
prepend?: string
4246
/**
4347
* The port to proxy.
4448
*/
@@ -826,10 +830,11 @@ export class HttpServer {
826830
// sure how best to get this information to the `proxyRes` event handler.
827831
// For now I'm sticking it on the request object which is passed through to
828832
// the event.
829-
;(request as ProxyRequest).base = options.base
833+
;(request as ProxyRequest).base = options.strip
830834

831835
const isHttp = response instanceof http.ServerResponse
832-
const path = options.base ? route.fullPath.replace(options.base, "") : route.fullPath
836+
const base = options.strip ? route.fullPath.replace(options.strip, "") : route.fullPath
837+
const path = normalize("/" + (options.prepend || "") + "/" + base, true)
833838
const proxyOptions: proxy.ServerOptions = {
834839
changeOrigin: true,
835840
ignorePath: true,

0 commit comments

Comments
 (0)