Caddy
Two handlers in your Caddyfile serve the script from your domain and pass its counts on, with the visitor’s address.
Add two handlers to your site’s block in the Caddyfile:
handle /js/tally.js {
reverse_proxy https://fiveb.ar {
header_up Host {upstream_hostport}
header_up -Cookie
header_up -Authorization
}
}
handle /api/tally {
reverse_proxy https://fiveb.ar {
header_up Host {upstream_hostport}
header_up X-Fivebar-IP {client_ip}
header_up -Cookie
header_up -Authorization
}
}Behind a load balancer or a CDN, list it in Caddy’s trusted_proxies, so that
{client_ip} is the visitor’s. See
Caddy’s help on reverse_proxy.
Load the script
Once the proxy is live, load the script from your own domain. It sends its counts to the host it was loaded from, so nothing else changes:
<script async data-domain="example.com" src="/js/tally.js"></script>Then check it works. If either path is already taken on your site, see Other paths. Proxying says how it works and which headers name the visitor.