If you are using Next.js, you can take advantage of rewrites to behave like a reverse proxy. To do so, add a rewrites()
function to your next.config.js
file:
JavaScript
// next.config.jsconst nextConfig = {async rewrites() {return [{source: "/ingest/:path*",destination: "https://app.posthog.com/:path*",},];},}module.exports = nextConfig
Then configure the PostHog client to send requests via your redirection.
JavaScript
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {api_host: "https://your-host.com/ingest"})