import { gatewayUrl } from '~/lib/server/gateway';

export async function GET({ params }: { params: { slug: string } }) {
  const upstream = gatewayUrl(`/api/kb/articles/${params.slug}`);
  try {
    const res = await fetch(upstream, { cache: 'no-store' });
    const body = await res.text();
    return new Response(body, {
      status: res.status,
      headers: { 'Content-Type': 'application/json' },
    });
  } catch (err: any) {
    return new Response(JSON.stringify({ error: err?.message || 'Gateway error' }), {
      status: 502,
      headers: { 'Content-Type': 'application/json' },
    });
  }
}
