Skip to main content

Plugin Utilities

createProxyHandler​

Creates a proxy middleware which proxies the given route to the given port. Useful for plugins which start their own servers but should be accessible via the main Vendure url.

Example

// Example usage in the `configuration` method of a VendurePlugin.
// Imagine that we have started a Node server on port 5678
// running some service which we want to access via the `/my-plugin/`
// route of the main Vendure server.
@VendurePlugin({
configuration: (config: Required<VendureConfig>) => {
config.apiOptions.middleware.push({
handler: createProxyHandler({
label: 'Admin UI',
route: 'my-plugin',
port: 5678,
}),
route: 'my-plugin',
});
return config;
}
})
export class MyPlugin {}
Signature
function createProxyHandler(options: ProxyOptions): RequestHandler

Parameters

options​

parameter

ProxyOptions​

Options to configure proxy middleware via createProxyHandler.

Signature
interface ProxyOptions {
label: string;
route: string;
port: number;
hostname?: string;
basePath?: string;
}

label​

property
string

A human-readable label for the service which is being proxied. Used to generate more informative logs.

route​

property
string

The route of the Vendure server which will act as the proxy url.

port​

property
number

The port on which the service being proxied is running.

hostname​

property
string
default:
'localhost'

The hostname of the server on which the service being proxied is running.

basePath​

property
string

An optional base path on the proxied server.