25 lines
550 B
TypeScript
25 lines
550 B
TypeScript
import { NextRequest } from "next/server";
|
|
import QRCode from "qrcode";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const url = req.nextUrl.searchParams.get("url") || "";
|
|
if (!url) {
|
|
return new Response("Missing url", { status: 400 });
|
|
}
|
|
|
|
const png = await QRCode.toBuffer(url, {
|
|
width: 240,
|
|
margin: 1
|
|
});
|
|
|
|
const body = new Uint8Array(png);
|
|
return new Response(body, {
|
|
headers: {
|
|
"Content-Type": "image/png",
|
|
"Cache-Control": "public, max-age=86400"
|
|
}
|
|
});
|
|
}
|