bud.proxy: options
You can pass a function to bud.proxy to manipulate all options. You must return them or the options will not be set!
bud.config.ts
bud.proxy((options = {}) => {
options.target = 'https://example.test'
return options
})
You can also pass an object to bud.proxy to set options. This will not overwrite unspecified defaults or options set elsewhere:
bud.config.ts
bud.proxy({
target: 'https://example.test',
changeOrigin: false,
})
Options can be specified as a second parameter (instead of the URL replacement array):
bud.config.ts
bud.proxy('https://example.test', {
changeOrigin: false,
})
Available options
See documentation of available options in the proxy middleware's README.
Below are the available options and their default values:
Option | Type | Default | Description |
---|---|---|---|
agent | Agent | undefined | The agent used for proxying |
auth | string | undefined | Basic authentication i.e. 'user:password' to compute an Authorization header |
autoRewrite | boolean | true | Automatically rewrite the location host/port |
buffer | Stream | undefined | A writable stream to serve as the response buffer |
changeOrigin | boolean | true | Changes the origin of the host header to the target URL |
cookieDomainRewrite | Record<string, string> | key is host set by bud.serve, value is the target host | Rewrite cookie domains |
cookiePathRewrite | Record<string, string> | undefined | Rewrite cookie paths |
ejectPlugins | boolean | undefined | Ejects all plugins |
followRedirects | boolean | false | Follow HTTP 3xx responses as redirects |
forward | URL | undefined | The URL to forward to. |
headers | Record<string, string> | undefined | Additional headers |
hostRewrite | string | Set by bud.serve | Rewrites the location hostname on (301 / 302 / 307 / 308) redirects |
ignorePath | boolean | undefined | Ignore the proxy path of the incoming request |
localAddress | string | undefined | Local interface string to bind for outgoing connections |
logger | Console | bud.js implementation | A logger object. Needs to implement warn , info , and error . |
on | Proxy Events | bud.js implementation | Event listeners. Note that setting this option will unset onProxyReq and onProxyRes |
onProxyReq | ProxyReqCallback | bud.js implementation | Callback function to modify the proxy request |
onProxyRes | ProxyResCallback | bud.js implementation | Callback function to modify the proxy response |
pathFilter | Array<string> | ['!/bud/**'] | Filters the paths to proxy |
pathRewrite | Record<string, string> | undefined | Rewrites the location path on (301 / 302 / 307 / 308) redirects |
plugins | Array<(proxyServer: HttpProxy, options: ServerOptions) => void> | undefined | Array of plugins to apply to the proxy server |
prependPath | boolean | undefined | Prepend the target's path to the proxy path |
preserveHeaderKeyCase | boolean | undefined | Preserve the case of response header keys |
protocolRewrite | http | https | https if the protocol of the URL set by bud.serve resolved to https: | Rewrites the location protocol on (301 / 302 / 307 / 308) redirects |
proxyTimeout | number | undefined | Specifies the number of milliseconds before the proxy times out |
replacements | Array<[string, string]> | A tuple with the target origin paired with the dev server origin | Replaces dev server url with proxy url in the response body. This will never be called if on or onProxyRequest is overridden |
router | Record<string, ProxyTargetUrl | ProxyTarget> | undefined | A map of regular expressions (string ) to proxy options |
secure | boolean | false | Verify that connection is secure |
selfHandleResponse | boolean | true | Self handle the response. If this is set to true (default) then the supplied onProxyRes must return a response |
ssl | HttpsServerOptions | undefined | SSL certificate options |
target | URL | http://0.0.0.0 | The target URL |
timeout | number | undefined | Specifies the number of milliseconds before the proxy response times out |
toProxy | boolean | true | Proxy to another server |
xfwd | boolean | undefined | Adds x-forward headers |
ws | boolean | undefined | Proxy websockets |