fix: posthog proxy config using rewrites

This commit is contained in:
sriram veeraghanta 2024-05-28 13:08:37 +05:30
parent e47ab573a7
commit a04ce5abfc
3 changed files with 9 additions and 8 deletions

View File

@ -8,7 +8,6 @@
"NEXT_PUBLIC_SPACE_BASE_URL",
"NEXT_PUBLIC_SPACE_BASE_PATH",
"NEXT_PUBLIC_WEB_BASE_URL",
"NEXT_PUBLIC_TRACK_EVENTS",
"NEXT_PUBLIC_PLAUSIBLE_DOMAIN",
"NEXT_PUBLIC_CRISP_ID",
"NEXT_PUBLIC_ENABLE_SESSION_RECORDER",

View File

@ -20,7 +20,7 @@ export interface IPosthogWrapper {
}
const PostHogProvider: FC<IPosthogWrapper> = (props) => {
const { children, user, workspaceRole, currentWorkspaceId, projectRole, posthogAPIKey, posthogHost } = props;
const { children, user, workspaceRole, currentWorkspaceId, projectRole } = props;
// states
const [lastWorkspaceId, setLastWorkspaceId] = useState(currentWorkspaceId);
// router
@ -42,15 +42,16 @@ const PostHogProvider: FC<IPosthogWrapper> = (props) => {
}, [user, workspaceRole, projectRole]);
useEffect(() => {
if (posthogAPIKey && (process.env.NEXT_PUBLIC_POSTHOG_HOST || posthogHost)) {
posthog.init(posthogAPIKey, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || posthogHost || "https://app.posthog.com",
if (process.env.NEXT_PUBLIC_POSTHOG_KEY && process.env.NEXT_PUBLIC_POSTHOG_HOST) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: "/ingest",
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
debug: process.env.NEXT_PUBLIC_POSTHOG_DEBUG === "1", // Debug mode based on the environment variable
autocapture: false,
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
});
}
}, [posthogAPIKey, posthogHost]);
}, []);
useEffect(() => {
// Join workspace group on workspace change

View File

@ -55,14 +55,15 @@ const nextConfig = {
]
},
async rewrites() {
const posthogHost = process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://app.posthog.com"
const rewrites = [
{
source: "/ingest/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
destination: `${posthogHost}/static/:path*`,
},
{
source: "/ingest/:path*",
destination: "https://us.i.posthog.com/:path*",
destination: `${posthogHost}/:path*`,
},
];
if (process.env.NEXT_PUBLIC_ADMIN_BASE_URL || process.env.NEXT_PUBLIC_ADMIN_BASE_PATH) {