YOUR_SITE_ID and YOUR_PROXY_PATH with your own values. Site settings › Installation shows both, with this code already filled in. Generate the site secret there too.
1
Install the package
2
Add the environment variables
In .env. Set HIGHSEAT_PATH for the build as well as the server, as a build argument in a Docker build.
.env
3
Add the proxy to your server entry
Answers the proxy path and hands every other request to the app. A file route named after the path does not work: a catch-all route such as $id matches it first. “cloudflare” assumes a proxied Cloudflare record in front of the site; behind nginx alone, use “nginx”.
src/server.ts
4
Give the browser the same path
vite.config.ts
5
Load the tracker from the path
src/routes/__root.tsx
Pick the IP preset
The code usescloudflare, which fits a site behind a proxied Cloudflare record, even with nginx or Traefik in between. Behind nginx alone, use nginx. Pick the IP preset lists every preset.
Why the server entry
A file route named after the proxy path does not work: a catch-all route such as$id matches the path first. The server entry sees the request before the router does.
Set the path for the build
Thedefine in vite.config.ts copies HIGHSEAT_PATH into the browser bundle, so <Highseat /> loads from the path the server answers. Set HIGHSEAT_PATH for the build as well as for the server, as a build argument in a Docker build. The define loads that one variable alone, so the site secret never reaches the bundle.
An app that reads the server entry’s options
fallback receives the request alone, so the app loses the options the server entry was called with. If your app reads them, create the proxy without fallback and route the path yourself. In the server entry’s fetch, call the proxy when the request’s pathname equals HIGHSEAT_PATH, and handler.fetch(request, options) for every other request.