feat: init
This commit is contained in:
26
routes/api/recipes/images/[image].ts
Normal file
26
routes/api/recipes/images/[image].ts
Normal file
@ -0,0 +1,26 @@
|
||||
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,
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user