import type { APIRoute, GetStaticPaths } from "astro";
import { APACHE_CONFIG } from "astro:env/server";

const htaccess = String.raw`
ErrorDocument 404 /404.html
RedirectMatch 301 ^/stories(/(index.html)?)?$ /stories/1/
Redirect 301 /story/ /stories/
Redirect 301 /game/ /games/
`.trim();

export const getStaticPaths: GetStaticPaths = async () => {
  if (APACHE_CONFIG) {
    return [{ params: { config: ".htaccess" }, props: { body: htaccess } }];
  }
  return [];
};

export const GET: APIRoute = ({ props: { body } }) => new Response(body);
