THIS IS A MODIFIED VERSION
The purpose of the modification is to cache the respond locally, when the end point is not available, this middleware will be able to server up the static content. This is particularly useful during development that end point might not be ready, and need to quickly test the UI with some data.
Another change is to update the syntax to Node ES6. Therefore this will not be suitable to any node environment prior to version 6.
Usage:
var connect = ;var url = ;var proxy = ; var app = ;app;// now requests to '/api/x/y/z' are proxied to 'https://example.com/endpoint/x/y/z' //same as example above but also uses a short hand string only parameterapp;
Documentation:
proxyMiddleware(options)
options
allows any options that are permitted on the http
or https
request options.
Other options:
route
: you can pass the route for connect middleware within the options, as well.via
: by default no via header is added. If you passtrue
for this option the local hostname will be used for the via header. You can also pass a string for this option in which case that will be used for the via header.cookieRewrite
: this option can be used to support cookies via the proxy by rewriting the cookie domain to that of the proxy server. By default cookie domains are not rewritten. ThecookieRewrite
option works as thevia
option - if you passtrue
the local hostname will be used, and if you pass a string that will be used as the rewritten cookie domain.preserveHost
: When enabled, this option will pass the Host: line from the incoming request to the proxied host. Default:false
.
Usage with route:
var proxyOptions = url;proxyOptionsroute = '/api'; var middleWares = /*, ...*/; // Grunt connect uses this method;