---
export const prerender = false; // since we're reading cookies

import { isValidFramework } from '@/types/docs';
import { getPreferencesServer } from '@/utils/docs/preferences';
import { resolveIndexRedirect } from '@/utils/docs/routing';

const { framework } = Astro.params;

if (!framework) {
  return Astro.redirect('/docs', 307);
}

if (!isValidFramework(framework)) {
  return new Response('Not Found', { status: 404 });
}

// astro check can't see usage inside return statements in frontmatter (false positive ts(6133))
const preferences = getPreferencesServer(Astro.cookies);
const { url } = resolveIndexRedirect({ preferences, params: { framework } });

return Astro.redirect(url, 307);
---
