Skip to content

Commit

Permalink
Update readme with proxy in front of proxy manual
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed May 13, 2020
1 parent f7c5487 commit 6dfcd12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,20 @@ Proxied: www.google-analytics.com/collect?v=1&_v=j73&a=531530768&t=pageview&_s=1

Check the [test-static/index.html](test-static/index.html) file's code to see how to bind the proxied analytics to your front end.

## Configuration
### Proxy in Front of the Proxy

Before the request hits this NodeJS app / container, you have to proxy/assign some useful headers to it (`host` and `x-real-ip` or `x-forwarded-for`). Below is the example of the minimal Nginx proxy configuration.

```
location /gtm-proxy/ {
proxy_set_header Host $host;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_pass http://app-address-running-in-your-infrastructure;
}
```

## Configuration

You can configure which third-parties to proxy/replace and how to do it in the config file. Find the actual configuration in [config.js](config.js) file:

Expand Down
2 changes: 1 addition & 1 deletion src/modules/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function createDefaultProxy (targetDomain, proxyOptionsOverride = {}) {
) {

const parsedUrl = url.parse(unmasked);
const pverwrittenIp = req.headers["x-forwarded-for"] || req.headers["x-real-ip"];
const pverwrittenIp = req.headers["x-forwarded-for"] || req.headers["x-real-ip"]; // TODO: || req.connection.remoteAddress; // in case no proxy is used (dedicated domain)
const clientIp = pverwrittenIp
? pverwrittenIp.split(/,\s?/g)[0]
: req.connection.remoteAddress.split(":").pop();
Expand Down

0 comments on commit 6dfcd12

Please sign in to comment.