Skip to content

Commit 3cd4cdd

Browse files
reverse proxy poshog, fix localstorage error
1 parent ae7d8a6 commit 3cd4cdd

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

next.config.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,25 @@ import "./src/env.js";
66

77
/** @type {import("next").NextConfig} */
88
const config = {
9-
reactStrictMode: false,
9+
reactStrictMode: false,
10+
async rewrites() {
11+
return [
12+
{
13+
source: "/ingest/static/:path*",
14+
destination: "https://us-assets.i.posthog.com/static/:path*",
15+
},
16+
{
17+
source: "/ingest/:path*",
18+
destination: "https://us.i.posthog.com/:path*",
19+
},
20+
{
21+
source: "/ingest/decide",
22+
destination: "https://us.i.posthog.com/decide",
23+
},
24+
];
25+
},
26+
// This is required to support PostHog trailing slash API requests
27+
skipTrailingSlashRedirect: true,
1028
};
1129

1230
export default config;

src/app/providers.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { PostHogProvider } from "posthog-js/react";
66
if (typeof window !== "undefined") {
77
// Only initialize PostHog if the environment variables are available
88
const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY;
9-
const posthogHost = process.env.NEXT_PUBLIC_POSTHOG_HOST;
9+
// const posthogHost = process.env.NEXT_PUBLIC_POSTHOG_HOST;
1010

11-
if (posthogKey && posthogHost) {
11+
if (posthogKey) {
1212
posthog.init(posthogKey, {
13-
api_host: posthogHost,
13+
api_host: "/ingest",
14+
ui_host: "https://us.posthog.com",
1415
person_profiles: "always",
1516
});
1617
} else {

src/hooks/useDiagram.ts

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function useDiagram(username: string, repo: string) {
5050
const [state, setState] = useState<StreamState>({ status: "idle" });
5151
const [hasUsedFreeGeneration, setHasUsedFreeGeneration] = useState<boolean>(
5252
() => {
53+
if (typeof window === "undefined") return false;
5354
return localStorage.getItem("has_used_free_generation") === "true";
5455
},
5556
);

0 commit comments

Comments
 (0)