aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/(app)/api')
-rw-r--r--src/routes/(app)/api/[...path]/+server.ts25
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) },
+ });
+}