Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/api/src/controllers/track.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FastifyReply, FastifyRequest } from 'fastify';
import { assocPath, pathOr, pick } from 'ramda';

import { HttpError } from '@/utils/errors';
import { generateId, slug } from '@openpanel/common';
import { generateDeviceId, parseUserAgent } from '@openpanel/common/server';
import { getProfileById, getSalts, upsertProfile } from '@openpanel/db';
Expand Down Expand Up @@ -187,9 +188,16 @@ export async function handler(
break;
}
case 'identify': {
const payload = request.body.payload;
const geo = await getGeoLocation(ip);
if (!payload.profileId) {
throw new HttpError('Missing profileId', {
status: 400,
});
}

await identify({
payload: request.body.payload,
payload,
projectId,
geo,
ua,
Expand Down
1 change: 1 addition & 0 deletions apps/start/src/hooks/use-app-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ export function useAppContext() {
apiUrl: params.apiUrl,
dashboardUrl: params.dashboardUrl,
isSelfHosted: params.isSelfHosted,
isMaintenance: params.isMaintenance ?? false,
};
}
1 change: 1 addition & 0 deletions apps/start/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface MyRouterContext {
apiUrl: string;
dashboardUrl: string;
isSelfHosted: boolean;
isMaintenance: boolean;
}

export const Route = createRootRouteWithContext<MyRouterContext>()({
Expand Down
27 changes: 27 additions & 0 deletions apps/start/src/routes/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { FullPageEmptyState } from '@/components/full-page-empty-state';
import { Sidebar } from '@/components/sidebar';
import { Button, LinkButton, buttonVariants } from '@/components/ui/button';
import { useAppContext } from '@/hooks/use-app-context';
import { cn } from '@/utils/cn';
import { Outlet, createFileRoute, redirect } from '@tanstack/react-router';
import { ConstructionIcon } from 'lucide-react';

export const Route = createFileRoute('/_app')({
beforeLoad: async ({ context }) => {
Expand All @@ -11,6 +16,28 @@ export const Route = createFileRoute('/_app')({
});

function AppLayout() {
const { isMaintenance } = useAppContext();

if (isMaintenance) {
return (
<FullPageEmptyState
icon={ConstructionIcon}
className="min-h-screen"
title="Maintenance mode"
description="We are currently performing maintenance on the system. Please check back later."
>
<a
href="https://status.openpanel.dev/"
className={cn(buttonVariants())}
target="_blank"
rel="noopener noreferrer"
>
Check out our status page
</a>
</FullPageEmptyState>
);
}

return (
<div className="flex h-screen w-full">
<Sidebar />
Expand Down
1 change: 1 addition & 0 deletions apps/start/src/server/get-envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const getServerEnvs = createServerFn().handler(async () => {
process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL,
),
isSelfHosted: process.env.SELF_HOSTED !== undefined,
isMaintenance: process.env.MAINTENANCE === '1',
};

return envs;
Expand Down
2 changes: 1 addition & 1 deletion apps/worker/src/boot-workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function bootWorkers() {
const worker = new GroupWorker<EventsQueuePayloadIncomingEvent['payload']>({
queue,
concurrency,
logger: queueLogger,
logger: process.env.NODE_ENV === 'production' ? queueLogger : undefined,
blockingTimeoutSec: Number.parseFloat(
process.env.EVENT_BLOCKING_TIMEOUT_SEC || '1',
),
Expand Down
4 changes: 4 additions & 0 deletions apps/worker/src/jobs/cron.ping.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { TABLE_NAMES, chQuery } from '@openpanel/db';

export async function ping() {
if (process.env.DISABLE_PING) {
return;
}
Comment on lines +4 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, check if the file exists and read the relevant lines
cat -n apps/worker/src/jobs/cron.ping.ts | head -20

Repository: Openpanel-dev/openpanel

Length of output: 787


🏁 Script executed:

# Search for other DISABLE_PING references in the codebase
rg "DISABLE_PING" --type ts --type tsx --type js --type jsx -B 2 -A 2

Repository: Openpanel-dev/openpanel

Length of output: 94


🏁 Script executed:

# Search for similar environment variable patterns in the codebase to understand conventions
rg "process\.env\." --type ts --type tsx --type js --type jsx | grep -E "if.*process\.env\." | head -20

Repository: Openpanel-dev/openpanel

Length of output: 94


🏁 Script executed:

# Search for DISABLE_PING in all files (any type)
rg "DISABLE_PING" -B 2 -A 2

Repository: Openpanel-dev/openpanel

Length of output: 318


🏁 Script executed:

# Check how other boolean-style env vars are handled in this codebase
rg "process\.env\." -A 0 | grep -E "(if|when|process\.env\.)" | head -30

Repository: Openpanel-dev/openpanel

Length of output: 2996


🏁 Script executed:

# Look for documentation files that might mention DISABLE_PING
fd -e md -e txt | xargs grep -l "DISABLE_PING" 2>/dev/null || echo "No matches found"

Repository: Openpanel-dev/openpanel

Length of output: 83


🏁 Script executed:

# Check environment variable patterns in the worker directory
rg "process\.env\." apps/worker/src -B 1 -A 1 | head -50

Repository: Openpanel-dev/openpanel

Length of output: 2107


Use consistent === undefined check for disable flag, matching codebase pattern.

The check process.env.DISABLE_PING uses JavaScript truthiness, which means any non-empty string (including "false" or "0") will disable the ping. More importantly, other disable flags in the codebase (DISABLE_BULLBOARD, DISABLE_WORKERS) check === undefined instead. Update to match:

-if (process.env.DISABLE_PING) {
+if (process.env.DISABLE_PING !== undefined) {
   return;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (process.env.DISABLE_PING) {
return;
}
if (process.env.DISABLE_PING !== undefined) {
return;
}
🤖 Prompt for AI Agents
In apps/worker/src/jobs/cron.ping.ts around lines 4-6, replace the truthy
environment check (if (process.env.DISABLE_PING) { return; }) with an explicit
undefined check so the flag is only considered set when the env var is present:
change the condition to if (process.env.DISABLE_PING !== undefined) { return; }
to match the codebase pattern of using ===/!== undefined for disable flags.


const [res] = await chQuery<{ count: number }>(
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`,
);
Expand Down
1 change: 0 additions & 1 deletion apps/worker/src/jobs/events.create-session-end.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export async function createSessionEnd(
...payload,
properties: {
...payload.properties,
...(session?.properties ?? {}),
__bounce: session.is_bounce,
},
name: 'session_end',
Expand Down
1 change: 0 additions & 1 deletion apps/worker/src/jobs/events.incoming-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ describe('incomingEvent', () => {
utm_content: '',
utm_medium: '',
revenue: 0,
properties: {},
project_id: projectId,
device_id: 'last-device-123',
profile_id: 'profile-123',
Expand Down
Loading