diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md index 247b11c..c8e6304 100644 --- a/.claude/CLAUDE.md +++ b/.claude/CLAUDE.md @@ -18,6 +18,7 @@ - ESLint must pass before committing - Import aliases: `@/` maps to `src/` - Bun as package manager (not npm/yarn/pnpm) +- **API paths: NEVER include `/api/` prefix.** The `api` client in `lib/api.ts` already has `baseUrl="/api"`. Write `api.get("/cases")` NOT `api.get("/api/cases")`. The client auto-strips accidental `/api/` prefixes but don't rely on it. ## General diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 5489787..3490808 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -4,6 +4,14 @@ import type { ApiError } from "@/lib/types"; class ApiClient { private baseUrl = "/api"; + /** Strip leading /api/ if accidentally included — baseUrl already provides it */ + private normalizePath(path: string): string { + if (path.startsWith("/api/")) { + return path.slice(4); // "/api/foo" -> "/foo" + } + return path; + } + private async getHeaders(): Promise { const supabase = createClient(); const { @@ -29,9 +37,10 @@ class ApiClient { } private async request( - path: string, + rawPath: string, options: RequestInit = {}, ): Promise { + const path = this.normalizePath(rawPath); const headers = await this.getHeaders(); const res = await fetch(`${this.baseUrl}${path}`, { ...options, @@ -80,7 +89,8 @@ class ApiClient { return this.request(path, { method: "DELETE" }); } - async postFormData(path: string, formData: FormData): Promise { + async postFormData(rawPath: string, formData: FormData): Promise { + const path = this.normalizePath(rawPath); const supabase = createClient(); const { data: { session },