Replace "@vercel/analytics" with "@tryghost/content-api" and add "node-fetch" to dependencies. Remove "@vercel/speed-insights" to streamline the package. Update robots.txt to dis access to "/legal-notice" and "/privacy-policy". Change <p> tags to <div> in the Privacy Policy for better structure. Update the last modified date in the Legal Notice. Add a new API route for fetching images with error handling for missing URL parameters.
36 lines
891 B
TypeScript
36 lines
891 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const { searchParams } = new URL(req.url);
|
|
const url = searchParams.get("url");
|
|
|
|
if (!url) {
|
|
return NextResponse.json(
|
|
{ error: "Missing URL parameter" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(url);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch image: ${response.statusText}`);
|
|
}
|
|
|
|
const contentType = response.headers.get("content-type");
|
|
const buffer = await response.arrayBuffer();
|
|
|
|
return new NextResponse(buffer, {
|
|
headers: {
|
|
"Content-Type": contentType || "application/octet-stream",
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error("Failed to fetch image:", error);
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch image" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|