Skip to content

Commit 4f1716a

Browse files
committed
feat: add /api/cleanup — delete expired redirects
1 parent 518b0f6 commit 4f1716a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

app/api/cleanup/route.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NextResponse } from 'next/server';
2+
import { sql } from '@/lib/db';
3+
4+
export async function GET() {
5+
try {
6+
const result = await sql`
7+
DELETE FROM redirects
8+
WHERE expires_at IS NOT NULL AND expires_at < NOW()
9+
`;
10+
return NextResponse.json({ deleted: result.rowCount });
11+
} catch (error) {
12+
console.error('Cleanup error:', error);
13+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
14+
}
15+
}

0 commit comments

Comments
 (0)