diff --git a/config.js b/config.js index 73b370b..0b73eab 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,7 @@ const MATCH_EVERYTHING_STRING = '.*'; const env = process.env.APP__ENV_NAME || "local"; const isLocal = env === "local" || env === "test"; +const proxyDomain = process.env.APP__PROXY_DOMAIN || ''; const strippedPath = process.env.APP__STRIPPED_PATH || ''; const hostsWhitelistRegex = (() => { try { @@ -12,7 +13,8 @@ const hostsWhitelistRegex = (() => { })(); console.log("Environment variables:"); -console.log(`APP__STRIPPED_PATH=${strippedPath} (path added to original host in analytics scripts)`); +console.log(`APP__PROXY_DOMAIN=${proxyDomain} (path added to original host replace proxy host`); +console.log(`APP__STRIPPED_PATH=${strippedPath} (proxy domain added to replace original host in analytics scripts)`); console.log(`APP__ENV_NAME=${env} (should not be local nor test in production)`); console.log(`APP__HOSTS_WHITELIST_REGEX=${hostsWhitelistRegex}${hostsWhitelistRegex.toString() === `/${MATCH_EVERYTHING_STRING}/` ? ' (YAY!! Anyone can use your proxy!)' : ''}`); @@ -21,9 +23,9 @@ export default { httpPort: process.env.PORT || 80, strippedPath, hostsWhitelistRegex: hostsWhitelistRegex, - proxyDomain: "", // Domain to proxy calls through. Leave it empty to use the requested domain as a proxy domain - proxy: { // Proxy configuration is here - domains: [ // These domains are replaced in any proxied response (including scripts, URLs and redirects) + proxyDomain, // Domain to proxy calls through. Leave it empty to use the requested domain as a proxy domain + proxy: { // Proxy configuration is here + domains: [ // These domains are replaced in any proxied response (including scripts, URLs and redirects) "adservice.google.com", "www.google-analytics.com", "analytics.google.com", diff --git a/readme.md b/readme.md index ebe06f5..6b5bce3 100644 --- a/readme.md +++ b/readme.md @@ -83,6 +83,13 @@ docker run -p 80:80 zitros/analytics-saviour Available environment variables: ```bash +APP__PROXY_DOMAIN=(empty string) +# The domain name used as a proxy for analytics scripts. +# +# When set, the traffic will be proxied via this domain. +# When not set, the current request domain is used as a proxy domain +# proxy URL requested by the browser is expected to be protocol://$APP__PROXY_DOMAIN$APP__STRIPPED_PATH/*(masked-url)*. + APP__STRIPPED_PATH=/gtm-proxy # A prefix which has been stripped in the request path reaching analytics-saviour. # If your ingress/router/etc strips the prefix you are required to set this variable.