Skip to content

Commit 1492cb3

Browse files
authored
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 9250088.
1 parent 0d0cfa3 commit 1492cb3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

config.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const MATCH_EVERYTHING_STRING = '.*';
22
const env = process.env.APP__ENV_NAME || "local";
33
const isLocal = env === "local" || env === "test";
4+
const proxyDomain = process.env.APP__PROXY_DOMAIN || '';
45
const strippedPath = process.env.APP__STRIPPED_PATH || '';
56
const hostsWhitelistRegex = (() => {
67
try {
@@ -12,7 +13,8 @@ const hostsWhitelistRegex = (() => {
1213
})();
1314

1415
console.log("Environment variables:");
15-
console.log(`APP__STRIPPED_PATH=${strippedPath} (path added to original host in analytics scripts)`);
16+
console.log(`APP__PROXY_DOMAIN=${proxyDomain} (path added to original host replace proxy host`);
17+
console.log(`APP__STRIPPED_PATH=${strippedPath} (proxy domain added to replace original host in analytics scripts)`);
1618
console.log(`APP__ENV_NAME=${env} (should not be local nor test in production)`);
1719
console.log(`APP__HOSTS_WHITELIST_REGEX=${hostsWhitelistRegex}${hostsWhitelistRegex.toString() === `/${MATCH_EVERYTHING_STRING}/` ? ' (YAY!! Anyone can use your proxy!)' : ''}`);
1820

@@ -21,9 +23,9 @@ export default {
2123
httpPort: process.env.PORT || 80,
2224
strippedPath,
2325
hostsWhitelistRegex: hostsWhitelistRegex,
24-
proxyDomain: "", // Domain to proxy calls through. Leave it empty to use the requested domain as a proxy domain
25-
proxy: { // Proxy configuration is here
26-
domains: [ // These domains are replaced in any proxied response (including scripts, URLs and redirects)
26+
proxyDomain, // Domain to proxy calls through. Leave it empty to use the requested domain as a proxy domain
27+
proxy: { // Proxy configuration is here
28+
domains: [ // These domains are replaced in any proxied response (including scripts, URLs and redirects)
2729
"adservice.google.com",
2830
"www.google-analytics.com",
2931
"analytics.google.com",

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ docker run -p 80:80 zitros/analytics-saviour
8383
Available environment variables:
8484

8585
```bash
86+
APP__PROXY_DOMAIN=(empty string)
87+
# The domain name used as a proxy for analytics scripts.
88+
#
89+
# When set, the traffic will be proxied via this domain.
90+
# When not set, the current request domain is used as a proxy domain
91+
# proxy URL requested by the browser is expected to be protocol://$APP__PROXY_DOMAIN$APP__STRIPPED_PATH/*(masked-url)*.
92+
8693
APP__STRIPPED_PATH=/gtm-proxy
8794
# A prefix which has been stripped in the request path reaching analytics-saviour.
8895
# If your ingress/router/etc strips the prefix you are required to set this variable.

0 commit comments

Comments
 (0)