Link route.

This commit is contained in:
Mike Cao 2025-08-18 22:30:22 -07:00
parent 2631fa51da
commit 789b8b36d8
4 changed files with 93 additions and 58 deletions

View file

@ -0,0 +1,37 @@
import { NextResponse } from 'next/server';
import { notFound } from '@/lib/response';
import { findLink } from '@/queries';
import { POST } from '@/app/api/send/route';
export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
const link = await findLink({
where: {
slug,
},
});
if (!link) {
return notFound();
}
const payload = {
type: 'event',
payload: {
link: link.id,
url: request.url,
referrer: request.referrer,
},
};
const req = new Request(request.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
await POST(req);
return NextResponse.redirect(link.url);
}

View file

@ -257,9 +257,7 @@ export async function POST(request: Request) {
lifatid,
twclid,
});
}
if (type === COLLECTION_TYPE.identify) {
} else if (type === COLLECTION_TYPE.identify) {
if (data) {
await saveSessionData({
websiteId,