Connecting to local network from Edge µGW with proxy tunneling enabled

The documentation specifies how to configure the µGW with a proxy_tunnel. When proxy_tunnel is true, Edge Microgateway uses the HTTP CONNECT method to tunnel HTTP requests over a single TCP connection. (The same is true if the environment variables for configuring the proxy are TLS enabled).

edge_config:    
  proxy: http://10.224.16.85:3128    
  proxy_tunnel:true

However, sometimes you may want some requests to go directly to a local network endpoint. For example, you may have a custom plugin that logs to a local syslog server.

To achieve this, follow the pattern used in some of the out of the box plugins. For example, the apikeys plugin. The code can be found at $node_modules_basedir/edgemicro/node_modules/microgateway-plugins/apikeys

1. At the top of your plugin code, import request library as 'requestLib'

var requestLib = require("request"); 

2. At the top of your init function, load the request library as a wrapper of the global request, if it exists, otherwise a new instance.

var request = config.request ? requestLib.defaults(config.request) : requestLib; 

This creates a wrapper of the request object that extends from the defaults set by the 'global' request object. I.e. it will inherit the proxy settings defined in the µGW yaml file. What you can then do is override the defaults of the wrapper so that it will only apply to the actual request being made.


For example:
var noProxyRequest = request.defaults({'proxy':''}); var forwardReq = noProxyRequest.post(options);

Version history
Last update:
‎04-01-2019 05:20 PM
Updated by: