Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

♻️ Refactor posthog shutdown call (#2002)

Luke Velladd25e52c95fe
diff --git a/apps/web/src/app/api/auth/[...nextauth]/route.ts b/apps/web/src/app/api/auth/[...nextauth]/route.ts
index 4b6eabc11..7a42cbe8b 100644
--- a/apps/web/src/app/api/auth/[...nextauth]/route.ts
+++ b/apps/web/src/app/api/auth/[...nextauth]/route.ts
@@ -1,5 +1,4 @@
import { handlers } from "@/next-auth";
-import { withPosthog } from "@/utils/posthog";
-export const GET = withPosthog(handlers.GET);
-export const POST = withPosthog(handlers.POST);
+export const GET = handlers.GET;
+export const POST = handlers.POST;
diff --git a/apps/web/src/app/api/stripe/webhook/route.ts b/apps/web/src/app/api/stripe/webhook/route.ts
index d9b0bf930..8724ef9be 100644
--- a/apps/web/src/app/api/stripe/webhook/route.ts
+++ b/apps/web/src/app/api/stripe/webhook/route.ts
@@ -1,15 +1,12 @@
import type { Stripe } from "@rallly/billing";
import { stripe } from "@rallly/billing";
-import { posthog } from "@rallly/posthog/server";
import * as Sentry from "@sentry/nextjs";
-import { waitUntil } from "@vercel/functions";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { isSelfHosted } from "@/utils/constants";
-import { withPosthog } from "@/utils/posthog";
import { getEventHandler } from "./handlers";
-export const POST = withPosthog(async (request: NextRequest) => {
+export const POST = async (request: NextRequest) => {
if (isSelfHosted) {
return NextResponse.json(
{ error: "This endpoint is not available on self-hosted instances" },
@@ -54,10 +51,6 @@ export const POST = withPosthog(async (request: NextRequest) => {
await handler(event);
- if (posthog) {
- waitUntil(posthog.flush());
- }
-
return NextResponse.json({ received: true });
} catch (err) {
Sentry.captureException(err);
@@ -68,4 +61,4 @@ export const POST = withPosthog(async (request: NextRequest) => {
{ status: 400 },
);
}
-});
+};
diff --git a/apps/web/src/utils/posthog.ts b/apps/web/src/utils/posthog.ts
deleted file mode 100644
index 400ba67d8..000000000
--- a/apps/web/src/utils/posthog.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-import { posthog } from "@rallly/posthog/server";
-import { waitUntil } from "@vercel/functions";
-import type { NextRequest } from "next/server";
-
-export function withPosthog(handler: (req: NextRequest) => Promise<Response>) {
- return async (req: NextRequest) => {
- const res = await handler(req);
- try {
- waitUntil(Promise.all([posthog?.shutdown()]));
- } catch (error) {
- console.error("Failed to flush PostHog events:", error);
- }
- return res;
- };
-}