mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Pixel route.
This commit is contained in:
parent
3c5c1e48e9
commit
0ac8bd41b6
10 changed files with 139 additions and 64 deletions
45
src/app/(collect)/p/[slug]/route.ts
Normal file
45
src/app/(collect)/p/[slug]/route.ts
Normal 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),
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue