From 1e9ed8fa128ec5ae038be14ef168cad37c1c0eb1 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 3 Mar 2026 22:45:50 -0800 Subject: api proxy --- src/routes/(app)/api/[...path]/+server.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/routes/(app)/api/[...path]/+server.ts (limited to 'src/routes/(app)/api') diff --git a/src/routes/(app)/api/[...path]/+server.ts b/src/routes/(app)/api/[...path]/+server.ts new file mode 100644 index 00000000..bc12494f --- /dev/null +++ b/src/routes/(app)/api/[...path]/+server.ts @@ -0,0 +1,25 @@ +import { PUBLIC_COINOS_URL as base } from "$env/static/public"; +import { auth } from "$lib/utils"; + +function getHeaders(cookies, request) { + const headers: Record = {}; + const authHeader = request.headers.get("authorization"); + if (authHeader) { + headers.authorization = authHeader; + } else { + Object.assign(headers, auth(cookies)); + } + return headers; +} + +export async function GET({ cookies, fetch, params, request }) { + return fetch(`${base}/${params.path}`, { headers: getHeaders(cookies, request) }); +} + +export async function POST({ cookies, fetch, params, request }) { + return fetch(`${base}/${params.path}`, { + method: "POST", + body: JSON.stringify(await request.json()), + headers: { "Content-Type": "application/json", ...getHeaders(cookies, request) }, + }); +} -- cgit v1.2.3