Skip to content

Commit 15791cd

Browse files
committed
Revert "lazily init ConvexHttpClient in strava webhook to fix preview builds"
This reverts commit cddc5e9.
1 parent cddc5e9 commit 15791cd

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

  • apps/web/app/api/webhooks/strava

apps/web/app/api/webhooks/strava/route.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ import { ConvexHttpClient } from "convex/browser";
33
import { api, internal } from "@repo/backend";
44
import { dateOnlyToUtcMs } from "@/lib/date-only";
55

6-
let _convex: ConvexHttpClient | null = null;
7-
function getConvex() {
8-
if (!_convex) {
9-
_convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);
10-
}
11-
return _convex;
12-
}
6+
const convex = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);
137

148
interface StravaWebhookEvent {
159
aspect_type: "create" | "update" | "delete";
@@ -100,7 +94,7 @@ export async function POST(request: NextRequest) {
10094
}
10195

10296
// Find user by Strava athlete ID
103-
const integrationData = await getConvex().query(
97+
const integrationData = await convex.query(
10498
internal.queries.integrations.getByAthleteId,
10599
{ athleteId: body.owner_id }
106100
);
@@ -117,7 +111,7 @@ export async function POST(request: NextRequest) {
117111
// Handle delete event
118112
if (body.aspect_type === "delete") {
119113
console.log("Processing delete for activity:", body.object_id);
120-
const result = await getConvex().mutation(
114+
const result = await convex.mutation(
121115
internal.mutations.stravaWebhook.deleteFromStrava,
122116
{ externalId: body.object_id.toString() }
123117
);
@@ -140,7 +134,7 @@ export async function POST(request: NextRequest) {
140134
}
141135

142136
// Refresh token if needed
143-
const refreshedToken = await getConvex().action(
137+
const refreshedToken = await convex.action(
144138
api.actions.strava.refreshToken,
145139
{
146140
integrationId: integration._id,
@@ -155,7 +149,7 @@ export async function POST(request: NextRequest) {
155149

156150
// Fetch activity details from Strava
157151
console.log("Fetching activity details from Strava:", body.object_id);
158-
const activity = (await getConvex().action(api.actions.strava.fetchActivity, {
152+
const activity = (await convex.action(api.actions.strava.fetchActivity, {
159153
accessToken: accessToken!,
160154
activityId: body.object_id,
161155
})) as StravaActivity;
@@ -169,7 +163,7 @@ export async function POST(request: NextRequest) {
169163
});
170164

171165
// Get user's challenge participations
172-
const participations = await getConvex().query(
166+
const participations = await convex.query(
173167
internal.mutations.stravaWebhook.getUserParticipations,
174168
{ userId: user._id }
175169
);
@@ -208,7 +202,7 @@ export async function POST(request: NextRequest) {
208202
console.log("Processing activity for challenge:", challenge._id);
209203

210204
// Create/update activity
211-
const result = await getConvex().mutation(
205+
const result = await convex.mutation(
212206
internal.mutations.stravaWebhook.createFromStrava,
213207
{
214208
userId: user._id,

0 commit comments

Comments
 (0)