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
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
// app/api/cron/sync-shared-data/route.ts
import { NextResponse } from 'next/server';
import { syncSharedData } from '@/lib/data-sync/aurora/shared-sync';
import { BoardRouteParameters, ParsedBoardRouteParameters } from '@/app/lib/types';
import { parseBoardRouteParams } from '@/app/lib/url-utils';

export const dynamic = 'force-dynamic';
export const maxDuration = 300;
// This is a simple way to secure the endpoint, should be replaced with a better solution
const CRON_SECRET = process.env.CRON_SECRET;

export async function GET(request: Request) {
export async function GET(request: Request, { params }: { params: BoardRouteParameters }) {
const { board_name }: ParsedBoardRouteParameters = parseBoardRouteParams(params);

try {
// Basic auth check
const authHeader = request.headers.get('authorization');
if (process.env.VERCEL_ENV !== 'development' && authHeader !== `Bearer ${CRON_SECRET}`) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}

// Sync both board types
const results = await Promise.all([
syncSharedData('tension'),
syncSharedData('kilter')
]);
const result = syncSharedData(board_name);

return NextResponse.json({
success: true,
results: {
tension: results[0],
kilter: results[1],
},
results: result,
});
} catch (error) {
console.error('Cron job failed:', error);
Expand Down
6 changes: 5 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"installCommand": "npm install --legacy-peer-deps",
"crons": [
{
"path": "/api/internal/shared-sync",
"path": "/api/internal/shared-sync/tension",
"schedule": "0 */2 * * *"
},
{
"path": "/api/internal/shared-sync/kilter",
"schedule": "15 */2 * * *"
}
]
}