Pixel route.

This commit is contained in:
Mike Cao 2025-08-18 15:49:10 -07:00
parent 3c5c1e48e9
commit 0ac8bd41b6
10 changed files with 139 additions and 64 deletions

View file

@ -0,0 +1,45 @@
import { NextResponse } from 'next/server';
import { notFound } from '@/lib/response';
import { findPixel } from '@/queries';
import { POST } from '@/app/api/send/route';
const image = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw', 'base64');
export async function GET(request: Request, { params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
const pixel = await findPixel({
where: {
slug,
},
});
if (!pixel) {
return notFound();
}
const payload = {
type: 'event',
payload: {
pixel: pixel.id,
url: request.url,
referrer: request.referrer,
},
};
const req = new Request(request.url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
const res = await POST(req);
return new NextResponse(image, {
headers: {
'Content-Type': 'image/gif',
'Content-Length': image.length.toString(),
'x-umami-collect': JSON.stringify(res),
},
});
}