Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ var server = app.listen(3000);
delete proxyRes.headers['x-removed']; // remove header from response
}
```
* **option.debugLog**: boolean, log to console when proxy-related events happen.

* (DEPRECATED) **option.proxyHost**: Use `option.changeOrigin = true` instead.

Expand Down
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var httpProxyMiddleware = function (context, opts) {

// create proxy
var proxy = httpProxy.createProxyServer(proxyOptions);
console.log('[HPM] Proxy created:', config.context, ' -> ', proxyOptions.target);
debugLog('[HPM] Proxy created:', config.context, ' -> ', proxyOptions.target);

var pathRewriter = PathRewriter.create(proxyOptions.pathRewrite); // returns undefined when "pathRewrite" is not provided

Expand All @@ -31,7 +31,7 @@ var httpProxyMiddleware = function (context, opts) {
// Listen for the `close` event on `proxy`.
proxy.on('close', function (req, socket, head) {
// view disconnected websocket connections
console.log('[HPM] Client disconnected');
debugLog('[HPM] Client disconnected');
});

// https://github.com/chimurai/http-proxy-middleware/issues/19
Expand Down Expand Up @@ -71,6 +71,12 @@ var httpProxyMiddleware = function (context, opts) {
}
}

function debugLog () {
if (proxyOptions.debugLog) {
console.log.apply(null, arguments);
}
}

function catchUpgradeRequest (server) {
// make sure only 1 handle listens to server's upgrade request.
if (isWsUpgradeListened === true) {
Expand All @@ -87,7 +93,7 @@ var httpProxyMiddleware = function (context, opts) {
req.url = pathRewriter(req.url);
}
proxy.ws(req, socket, head);
console.log('[HPM] Upgrading to WebSocket');
debugLog('[HPM] Upgrading to WebSocket');
}
}

Expand All @@ -101,7 +107,7 @@ var httpProxyMiddleware = function (context, opts) {

function proxyErrorLogger (err, req, res) {
var targetUri = proxyOptions.target.host + req.url;
console.log('[HPM] Proxy error:', err.code, targetUri);
debugLog('[HPM] Proxy error:', err.code, targetUri);
}

};
Expand Down