---
import { Root } from '../components/Root'
import Prerendered from '../main.astro'
import { apiClient } from '../utils/apiClient'
import { initRouter } from '../stores/router'

const slug = Astro.params.slug?.toString()
if (slug.endsWith('.map')) {
  return Astro.redirect('/404')
}

const article = await apiClient.getShout(slug)
if (!article) {
  return Astro.redirect('/404')
}

const { pathname, search } = Astro.url
initRouter(pathname, search)

Astro.response.headers.set('Cache-Control', 's-maxage=1, stale-while-revalidate')
---

<Prerendered>
  <Root article={article} client:load />
</Prerendered>
