import type { NextApiRequest, NextApiResponse } from "next";
import { renderTrpcPanel } from "trpc-ui";
import { env } from "~/env.mjs";
import { appRouter } from "~/server/api/root";

export default async function handler(_: NextApiRequest, res: NextApiResponse) {
  if (!env.NEXT_PUBLIC_BASE_URL.includes("localhost")) {
    return res.status(404).send("Not Found");
  }
  res.status(200).send(
    renderTrpcPanel(appRouter, {
      url: `${env.NEXT_PUBLIC_BASE_URL}/api/trpc`,
      transformer: "superjson",
    }),
  );
}
