Files
claudemesh/packages/api/src/index.ts
Alejandro Gutiérrez 8b5708a604
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled
fix(api): mount /v1 router via .route, not basePath
2026-05-02 02:22:08 +01:00

65 lines
2.1 KiB
TypeScript

import { Hono } from "hono";
import { some } from "hono/combine";
import { cors } from "hono/cors";
import { csrf } from "hono/csrf";
import { logger as loggerMiddleware } from "hono/logger";
import { auth } from "@turbostarter/auth/server";
import { logger } from "@turbostarter/shared/logger";
import { matchesPattern } from "@turbostarter/shared/utils";
import { localize, delay } from "./middleware";
import { adminRouter } from "./modules/admin/router";
// import { aiRouter } from "./modules/ai/router"; // disabled: @turbostarter/ai package removed in claudemesh
import { authRouter } from "./modules/auth/router";
import { billingRouter } from "./modules/billing/router";
import { myRouter } from "./modules/mesh/router";
import { v1Router } from "./modules/mesh/v1-router";
import { organizationRouter } from "./modules/organization/router";
import { publicRouter } from "./modules/public/router";
import { storageRouter } from "./modules/storage/router";
import { onError } from "./utils/on-error";
import type { Context } from "hono";
const appRouter = new Hono()
.basePath("/api")
.use(
some(
(c: Context) => !!c.req.header("x-client-platform")?.startsWith("mobile"),
csrf({
origin: (origin, c) =>
[...auth.options.trustedOrigins, new URL(c.req.url).origin].some(
(trustedOrigin) => matchesPattern(origin, trustedOrigin),
),
}),
),
)
.use(
cors({
origin: "*",
allowHeaders: ["Content-Type", "Authorization"],
maxAge: 3600,
credentials: true,
}),
)
.use(loggerMiddleware((...args) => logger.info(...args)))
.use(delay)
.use(localize)
.get("/health", (c) => c.json({ status: "ok" }))
.route("/admin", adminRouter)
// .route("/ai", aiRouter) // disabled: @turbostarter/ai package removed in claudemesh
.route("/auth", authRouter)
.route("/billing", billingRouter)
.route("/my", myRouter)
.route("/v1", v1Router)
.route("/organizations", organizationRouter)
.route("/public", publicRouter)
.route("/storage", storageRouter)
.onError(onError);
type AppRouter = typeof appRouter;
export type { AppRouter };
export { appRouter };