Package Exports
- @mocks-server/plugin-proxy
- @mocks-server/plugin-proxy/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mocks-server/plugin-proxy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Mocks Server Plugin Proxy
Plugin for Mocks Server that provides a route handler that proxy requests to another host and pass response back to original caller.
It uses the express-http-proxy package under the hood, and supports all of its options.
Usage
This plugin is included in the main distribution of the Mocks Server project, so you can also read the official documentation website.
Proxy routes
If you want a route variant to use the proxy handler, define its handler property as "proxy". Use the host property to set the host for the route, and the options property to set any of the express-http-proxy options.
module.exports = [
{
id: "proxy-all",
url: "*",
method: ["GET", "POST", "PATCH", "PUT"],
variants: [
{
id: "proxy-to-google",
handler: "proxy", // This route variant will use the "proxy" handler from this plugin
host: "https://www.google.com", // proxy host
options: {} // Options for express-http-proxy
},
{
id: "disabled",
response: (req, res, next) => next(),
},
],
},
];Route variant options
Mocks server common properties to all route handlers are in cursive. Specific properties of this plugin are in bold:
id(String): Id of the route variant.handler(String): Must be "proxy" to let this plugin handle the route.delay(Number|null): Milliseconds of delay for this variant.host(String|Function): The proxy host. Equivalent to theexpress-http-proxyhostoption, so it can also be a function.options(Object): Object containing any of the options supported by theexpress-http-proxypackage. Some of them are:- filter (Function):
filteroption forexpress-http-proxy. - userResDecorator (Function):
userResDecoratoroption forexpress-http-proxy. - ... all other
express-http-proxyoptions are also supported.
- filter (Function):
Tip: Note that the
delayoption is still valid for routes handled by this plugin, so you can use it to simulate that host responses are slow.
