Skip to content

Commit bdbc0d8

Browse files
committed
fix(api): mount Autumn at /api/autumn so OpenAPI docs are not hijacked
Elysia mount(autumnHandler) as a single function registered ALL /* and returned Autumn 404 for / and /spec.json. Mount under /api/autumn with path rewrite to match Autumn router and React provider defaults.
1 parent f5e4420 commit bdbc0d8

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

.agents/skills/databuddy/references/codebase-map.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Use this file when the task spans multiple packages or when the right edit locat
2222

2323
- Elysia API service
2424
- Default dev port: `3001`
25+
- **Autumn (`autumn-js/fetch`)**: Do not `mount(autumnHandler(...))` with a single argument — Elysia treats that as a catch‑all `/*` and Autumn returns `{"code":"not_found",...}` for every non‑Autumn path (breaks OpenAPI docs at `/` and `/spec.json`). Mount at `/api/autumn` and pass requests through `withAutumnApiPath` so routed paths stay under `/api/autumn` (see [`apps/api/src/lib/autumn-mount.ts`](/Users/iza/Dev/Databuddy/apps/api/src/lib/autumn-mount.ts)).
2526
- AI insights: [`apps/api/src/routes/insights.ts`](/Users/iza/Dev/Databuddy/apps/api/src/routes/insights.ts) — Top Pages rows include a **Human label** (opaque path segments → “Demo page”, etc.); system prompt asks for risk/watch insights in good weeks and data-grounded suggestions. Dashboard [`insight-card`](/Users/iza/Dev/Databuddy/apps/dashboard/app/(main)/insights/_components/insight-card.tsx): **Ask agent** + path-aware **View events** (`/events/stream?path=…` when a path is parsed from copy). Dedupes on cooldown-window DB keys `(websiteId|type|direction)`; failed insert returns no new insights. Funnel/MRR/retention insights require those metrics in query data—do not invent in prompts alone.
2627
- Handles routes such as public endpoints, webhooks, health, query, MCP, and agent-related APIs
2728
- Typical work:

apps/api/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Elysia } from "elysia";
1818
import { initLogger, log, parseError } from "evlog";
1919
import { evlog, useLogger } from "evlog/elysia";
2020
import { applyAuthWideEvent } from "@/lib/auth-wide-event";
21+
import { AUTUMN_API_PREFIX, withAutumnApiPath } from "@/lib/autumn-mount";
2122
import {
2223
apiLoggerDrain,
2324
enrichApiWideEvent,
@@ -278,7 +279,7 @@ const app = new Elysia({ precompile: true })
278279
})
279280
)
280281
.use(webhooks)
281-
.mount(
282+
.mount(AUTUMN_API_PREFIX, (request) =>
282283
autumnHandler({
283284
identify: async (request) => {
284285
try {
@@ -313,7 +314,7 @@ const app = new Elysia({ precompile: true })
313314
return null;
314315
}
315316
},
316-
})
317+
})(withAutumnApiPath(request))
317318
)
318319
.use(query)
319320
.use(agent)

apps/api/src/lib/autumn-mount.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** Elysia `.mount("/api/autumn", …)` strips the prefix, so the inner pathname is `/attach` not `/api/autumn/attach`. Autumn's router matches full paths under `/api/autumn`. */
2+
const AUTUMN_API_PREFIX = "/api/autumn";
3+
4+
export function withAutumnApiPath(request: Request): Request {
5+
const url = new URL(request.url);
6+
const path = `${AUTUMN_API_PREFIX}${url.pathname === "/" ? "" : url.pathname}`;
7+
return new Request(new URL(path + url.search, url.origin), request);
8+
}
9+
10+
export { AUTUMN_API_PREFIX };

0 commit comments

Comments
 (0)