first action update user pages .
2-update driver pages [fixed image display and notyfi] 3-update car pages [fixed image] 4-build tripe pages crud 5-build some role pages 6-build audit page 7-update ui compounants 8-update saidebar and topbar 9-cheange view to be ar view 10-cheange stractcher to be app,src 11-add validation layer by yup 12-add api image-proxy to broke image corse bloken
This commit is contained in:
35
app/api/proxy-image/[...imagePath]/route.ts
Normal file
35
app/api/proxy-image/[...imagePath]/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const BACKEND_BASE = "https://logiapi.slash.sa";
|
||||
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ filename: string }> },
|
||||
) {
|
||||
const { filename } = await params;
|
||||
|
||||
try {
|
||||
const upstream = await fetch(
|
||||
`${BACKEND_BASE}/public/uploads/driver-photos/${filename}`,
|
||||
{ cache: "no-store" },
|
||||
);
|
||||
|
||||
if (!upstream.ok) {
|
||||
return new NextResponse(null, { status: upstream.status });
|
||||
}
|
||||
|
||||
const buffer = await upstream.arrayBuffer();
|
||||
const contentType =
|
||||
upstream.headers.get("Content-Type") ?? "image/jpeg";
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": "public, max-age=3600, stale-while-revalidate=86400",
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return new NextResponse(null, { status: 502 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user