diff options
| author | Adam Soltys <[email protected]> | 2026-03-03 22:45:50 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-03-03 22:45:50 -0800 |
| commit | 1e9ed8fa128ec5ae038be14ef168cad37c1c0eb1 (patch) | |
| tree | 29399a82df3f981a24ef6cc84562c8ee006738d7 /src/routes/(app)/api | |
| parent | e66a08d18f2bef2eccfe84042a2674141a73d1c2 (diff) | |
| download | coinos-ui-1e9ed8fa128ec5ae038be14ef168cad37c1c0eb1.tar.gz coinos-ui-1e9ed8fa128ec5ae038be14ef168cad37c1c0eb1.zip | |
api proxy
Diffstat (limited to 'src/routes/(app)/api')
| -rw-r--r-- | src/routes/(app)/api/[...path]/+server.ts | 25 |
1 files changed, 25 insertions, 0 deletions
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<string, string> = {}; + 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) }, + }); +} |
