♻️ Migrate og image api routes to app dir (#1586)

This commit is contained in:
Luke Vella 2025-02-28 09:42:29 +00:00 committed by GitHub
parent aebea5a41c
commit 83e3d85c97
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 10 deletions

View file

@ -2,9 +2,7 @@
import { ImageResponse } from "next/og"; import { ImageResponse } from "next/og";
import type { NextRequest } from "next/server"; import type { NextRequest } from "next/server";
export const config = { export const runtime = "edge";
runtime: "edge",
};
const regularFont = fetch( const regularFont = fetch(
new URL("/public/static/fonts/inter-regular.ttf", import.meta.url), new URL("/public/static/fonts/inter-regular.ttf", import.meta.url),
@ -14,13 +12,13 @@ const boldFont = fetch(
new URL("/public/static/fonts/inter-bold.ttf", import.meta.url), new URL("/public/static/fonts/inter-bold.ttf", import.meta.url),
).then((res) => res.arrayBuffer()); ).then((res) => res.arrayBuffer());
export default async function handler(req: NextRequest) { export async function GET(req: NextRequest) {
const [regularFontData, boldFontData] = await Promise.all([ const [regularFontData, boldFontData] = await Promise.all([
regularFont, regularFont,
boldFont, boldFont,
]); ]);
const { searchParams } = req.nextUrl; const { searchParams } = new URL(req.url);
const title = searchParams.get("title"); const title = searchParams.get("title");
const excerpt = searchParams.get("excerpt"); const excerpt = searchParams.get("excerpt");

View file

@ -8,9 +8,7 @@ const schema = z.object({
author: z.string().min(1), author: z.string().min(1),
}); });
export const config = { export const runtime = "edge";
runtime: "edge",
};
const regularFont = fetch( const regularFont = fetch(
new URL("/public/static/fonts/inter-regular.ttf", import.meta.url), new URL("/public/static/fonts/inter-regular.ttf", import.meta.url),
@ -20,12 +18,13 @@ const boldFont = fetch(
new URL("/public/static/fonts/inter-bold.ttf", import.meta.url), new URL("/public/static/fonts/inter-bold.ttf", import.meta.url),
).then((res) => res.arrayBuffer()); ).then((res) => res.arrayBuffer());
export default async function handler(req: NextRequest) { export async function GET(req: NextRequest) {
const [regularFontData, boldFontData] = await Promise.all([ const [regularFontData, boldFontData] = await Promise.all([
regularFont, regularFont,
boldFont, boldFont,
]); ]);
const { searchParams } = req.nextUrl;
const { searchParams } = new URL(req.url);
const { title, author } = schema.parse({ const { title, author } = schema.parse({
title: searchParams.get("title"), title: searchParams.get("title"),