23 lines
716 B
TypeScript
23 lines
716 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { authenticate } from '@/app/lib/utils';
|
|
import { syncAllDomains } from '@/app/lib/sync';
|
|
|
|
export async function POST(req: NextRequest) {
|
|
if (!authenticate(req)) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
|
|
try {
|
|
// Start sync in background (don't wait for completion)
|
|
syncAllDomains().catch(err => {
|
|
console.error('Sync failed:', err);
|
|
});
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: 'Sync started in background'
|
|
});
|
|
} catch (error) {
|
|
console.error('Error starting sync:', error);
|
|
return NextResponse.json({ error: 'Failed to start sync' }, { status: 500 });
|
|
}
|
|
}
|