import { env } from '$env/dynamic/public';

/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) {
  // Attach the backend API URL to locals for server-side fetches.
  event.locals.api_url = env.PUBLIC_API_URL || 'http://localhost:8000';
  return resolve(event);
}

/** @type {import('@sveltejs/kit').HandleServerError} */
export function handleError({ error }) {
  console.error('Server error:', error);
  return { message: 'Internal error' };
}