feat: add goal proxy API route

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Sanju Sivalingam
2026-02-17 14:45:52 +05:30
parent 7557481e83
commit 84af22e4a1

View File

@@ -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());
};