Skip to content

Commit

Permalink
Add APP__PROXY_DOMAIN environment variable (#23)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
stegano authored Dec 3, 2020
1 parent 0d0cfa3 commit 1492cb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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!)' : ''}`);

Expand All @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1492cb3

Please sign in to comment.