From 7c2ca7d03e30448f095e340f9d478db96c070f03 Mon Sep 17 00:00:00 2001 From: Asher Date: Thu, 23 Jul 2020 12:37:45 -0500 Subject: [PATCH] Add the ability to prepend to the proxy path This is for applications like Jupyter that aren't base path agnostic. --- src/node/app/proxy.ts | 4 ++-- src/node/http.ts | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/node/app/proxy.ts b/src/node/app/proxy.ts index 14647b8fd..a332cc055 100644 --- a/src/node/app/proxy.ts +++ b/src/node/app/proxy.ts @@ -24,7 +24,7 @@ export class ProxyHttpProvider extends HttpProvider { const port = route.base.replace(/^\//, "") return { proxy: { - base: `${route.providerBase}/${port}`, + strip: `${route.providerBase}/${port}`, port, }, } @@ -35,7 +35,7 @@ export class ProxyHttpProvider extends HttpProvider { const port = route.base.replace(/^\//, "") return { proxy: { - base: `${route.providerBase}/${port}`, + strip: `${route.providerBase}/${port}`, port, }, } diff --git a/src/node/http.ts b/src/node/http.ts index 62abeb07e..313ecbeba 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -36,9 +36,13 @@ export type Query = { [key: string]: string | string[] | undefined } export interface ProxyOptions { /** - * A base path to strip from from the request before proxying if necessary. + * A path to strip from from the beginning of the request before proxying */ - base?: string + strip?: string + /** + * A path to add to the beginning of the request before proxying. + */ + prepend?: string /** * The port to proxy. */ @@ -826,10 +830,11 @@ export class HttpServer { // sure how best to get this information to the `proxyRes` event handler. // For now I'm sticking it on the request object which is passed through to // the event. - ;(request as ProxyRequest).base = options.base + ;(request as ProxyRequest).base = options.strip const isHttp = response instanceof http.ServerResponse - const path = options.base ? route.fullPath.replace(options.base, "") : route.fullPath + const base = options.strip ? route.fullPath.replace(options.strip, "") : route.fullPath + const path = normalize("/" + (options.prepend || "") + "/" + base, true) const proxyOptions: proxy.ServerOptions = { changeOrigin: true, ignorePath: true,