short-url/app/api/url/[shortCode]/route.ts
2024-11-26 12:45:06 +08:00

18 lines
487 B
TypeScript

import { NextResponse } from 'next/server';
import { getLongUrl, getUrlStats } from '@/lib/db';
export async function GET(
request: Request,
{ params }: { params: { shortCode: string } }
) {
const { longUrl, expired } = getLongUrl(params.shortCode);
const stats = getUrlStats(params.shortCode);
if (longUrl) {
return NextResponse.json({ longUrl, expired, stats });
} else {
return NextResponse.json({ longUrl: null, expired, stats: null }, { status: 404 });
}
}