27 lines
658 B
TypeScript
27 lines
658 B
TypeScript
import { chQuery, TABLE_NAMES } from '@openpanel/db';
|
|
|
|
export async function ping() {
|
|
const [res] = await chQuery<{ count: number }>(
|
|
`SELECT COUNT(*) as count FROM ${TABLE_NAMES.events}`
|
|
);
|
|
|
|
if (typeof res?.count === 'number') {
|
|
const response = await fetch('https://api.openpanel.com/misc/ping', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
domain: process.env.NEXT_PUBLIC_DASHBOARD_URL,
|
|
count: res?.count,
|
|
}),
|
|
});
|
|
|
|
if (response.ok) {
|
|
return await response.json();
|
|
}
|
|
|
|
throw new Error('Failed to ping the server');
|
|
}
|
|
}
|