import { Hono } from "hono";

import { rpcApp } from "./routes/rpc";
import { clientEntry } from "./routes/client-entry";

const app = new Hono();

// Allow all hosts for Tailscale Funnel
app.use("*", async (c, next) => {
  // Accept requests from any host
  return next();
});

// Health check endpoint
app.get("/health", (c) => {
  return c.json({ status: "ok", timestamp: new Date().toISOString() });
});

// Legal config endpoint (temporary fix for RPC issue)
app.get("/api/legal-config", async (c) => {
  try {
    const { getLegalConfig } = await import("./lib/legal-config");
    const config = getLegalConfig();
    return c.json(config);
  } catch (error) {
    console.error("Legal config error:", error);
    return c.json({ error: "Failed to load legal config" }, 500);
  }
});

app.route("/rpc", rpcApp);
app.get("/*", clientEntry);

export default app;
