Archived
1
0

Add the ability to prepend to the proxy path

This is for applications like Jupyter that aren't base path agnostic.
This commit is contained in:
Asher 2020-07-23 12:37:45 -05:00
parent c67d31580f
commit 7c2ca7d03e
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 11 additions and 6 deletions

View File

@ -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,
},
}

View File

@ -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,