Files
arjmand-pharmacy/app/assets/images/[...path]/route.ts
T
Alireza HassaniandCursor cd2f9dfc9d Add Arjmand Pharmacy Next.js homepage.
Initial RTL storefront with header, slider, product sections, and local image assets.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-16 17:15:14 +03:30

38 lines
1.0 KiB
TypeScript

import { NextRequest } from "next/server";
import fs from "fs";
import path from "path";
const IMAGES_ROOT = path.join(process.cwd(), "src/assets/images");
const MIME: Record<string, string> = {
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".webp": "image/webp",
".gif": "image/gif",
".avif": "image/avif",
".svg": "image/svg+xml",
};
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ path: string[] }> },
) {
const segments = (await params).path.map((part) => decodeURIComponent(part));
const filePath = path.resolve(IMAGES_ROOT, ...segments);
if (!filePath.startsWith(IMAGES_ROOT + path.sep) || !fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
return new Response("Not found", { status: 404 });
}
const ext = path.extname(filePath).toLowerCase();
const body = fs.readFileSync(filePath);
return new Response(body, {
headers: {
"Content-Type": MIME[ext] ?? "application/octet-stream",
"Cache-Control": "public, max-age=3600",
},
});
}