Finally! Using an Astro API Route to handle all the queries which works like a dream. Also created a custom function to get the relative path for image files, fixing any external access issues. Co-authored-by: june <self@breadone.net> Co-committed-by: june <self@breadone.net>
16 lines
490 B
TypeScript
16 lines
490 B
TypeScript
import type { APIRoute } from "astro";
|
|
|
|
// THANK YOU https://stackoverflow.com/a/77297521 !!!!!!!
|
|
|
|
const getProxyUrl = (request: Request) => {
|
|
const proxyUrl = new URL(import.meta.env.PUBLIC_PB_URL);
|
|
const requestUrl = new URL(request.url);
|
|
|
|
return new URL(requestUrl.pathname, proxyUrl);
|
|
};
|
|
|
|
export const ALL: APIRoute = async ({ request }) => {
|
|
const proxyUrl = getProxyUrl(request);
|
|
const response = await fetch(proxyUrl.href, request);
|
|
return new Response(response.body);
|
|
}; |