From 1492cb3f6595a97b2a4e7cc8ace83a34963c753c Mon Sep 17 00:00:00 2001 From: Yongwoo Jung Date: Thu, 3 Dec 2020 22:33:05 +0900 Subject: [PATCH] Add `APP__PROXY_DOMAIN` environment variable (#23) * fix(config.js): add `APP__PROXY_DOMAIN` environment variable You can change the `proxyDomain` value through environment variables without directly modifying the source code. * docs(readme.md): add `APP__PROXY_DOMAIN` environment variable description * fix(Dockerfile): add environment variables Changed so that setting information can be changed using environment variables during build. * docs(readme.md): update `APP__PROXY_DOMAIN` environment variable description * Revert "fix(Dockerfile): add environment variables" This reverts commit 92500885c21a3005beb782b2f11fc98eedf6306a. --- config.js | 10 ++++++---- readme.md | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) 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.