From 84af22e4a1477723a2349f7658019a2a528600f4 Mon Sep 17 00:00:00 2001 From: Sanju Sivalingam Date: Tue, 17 Feb 2026 14:45:52 +0530 Subject: [PATCH] feat: add goal proxy API route Co-Authored-By: Claude Opus 4.6 --- web/src/routes/api/goals/+server.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 web/src/routes/api/goals/+server.ts diff --git a/web/src/routes/api/goals/+server.ts b/web/src/routes/api/goals/+server.ts new file mode 100644 index 0000000..34b13e3 --- /dev/null +++ b/web/src/routes/api/goals/+server.ts @@ -0,0 +1,29 @@ +import { json, error } from '@sveltejs/kit'; +import { env } from '$env/dynamic/private'; +import type { RequestHandler } from './$types'; + +const SERVER_URL = env.SERVER_URL || 'http://localhost:8080'; + +export const POST: RequestHandler = async ({ request, locals }) => { + if (!locals.user) { + return error(401, 'Unauthorized'); + } + + const body = await request.json(); + + const res = await fetch(`${SERVER_URL}/goals`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + cookie: request.headers.get('cookie') ?? '' + }, + body: JSON.stringify(body) + }); + + if (!res.ok) { + const err = await res.json().catch(() => ({ error: 'Unknown error' })); + return error(res.status, err.error ?? 'Failed to submit goal'); + } + + return json(await res.json()); +};