27 lines
764 B
TypeScript
27 lines
764 B
TypeScript
|
import { HandlerContext } from "$fresh/server.ts";
|
||
|
|
||
|
function copyHeader(headerName: string, to: Headers, from: Headers) {
|
||
|
const hdrVal = from.get(headerName);
|
||
|
if (hdrVal) {
|
||
|
to.set(headerName, hdrVal);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const handler = async (
|
||
|
_req: Request,
|
||
|
_ctx: HandlerContext,
|
||
|
): Promise<Response> => {
|
||
|
const proxyRes = await fetch(
|
||
|
"http://192.168.178.56:3007/Recipes/images/" + _ctx.params.image,
|
||
|
);
|
||
|
console.log({ params: _ctx.params });
|
||
|
const headers = new Headers();
|
||
|
copyHeader("content-length", headers, proxyRes.headers);
|
||
|
copyHeader("content-type", headers, proxyRes.headers);
|
||
|
copyHeader("content-disposition", headers, proxyRes.headers);
|
||
|
return new Response(proxyRes.body, {
|
||
|
status: proxyRes.status,
|
||
|
headers,
|
||
|
});
|
||
|
};
|