[PIE-14] More robust API proxy (!7)

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>
This commit was merged in pull request #7.
This commit is contained in:
2025-08-13 17:54:45 +12:00
committed by June
parent b8de3e82e9
commit 3c0e9dc0dd
7 changed files with 28 additions and 17 deletions

View File

@@ -0,0 +1,16 @@
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);
};