Custom API client to handle a lot of the more type safe queries Reviewed-on: #12 Co-authored-by: june <self@breadone.net> Co-committed-by: june <self@breadone.net>
15 lines
509 B
TypeScript
15 lines
509 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 + requestUrl.search, proxyUrl);
|
|
};
|
|
|
|
export const ALL: APIRoute = async ({ request }) => {
|
|
const proxyUrl = getProxyUrl(request);
|
|
const response = await fetch(proxyUrl.href, request);
|
|
return new Response(response.body);
|
|
}; |