fix: route ordering for /api/tasks/reorder endpoint

Static routes (/api/tasks/reorder, /api/tasks/cleanup) must be defined
before parameterized routes (/api/tasks/:id) to prevent Bun's router
from matching the parameter route first. This was causing 404 errors
on drag-and-drop task reordering in the kanban board.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2025-12-04 04:45:36 -08:00
parent a1987d4ed5
commit 4e5257481c
1 changed files with 10 additions and 9 deletions

View File

@ -167,10 +167,20 @@ export class BacklogServer {
"/settings": indexHtml, "/settings": indexHtml,
// API Routes using Bun's native route syntax // API Routes using Bun's native route syntax
// IMPORTANT: Static routes must come BEFORE parameterized routes to avoid `:id` matching literal paths
"/api/tasks": { "/api/tasks": {
GET: async (req: Request) => await this.handleListTasks(req), GET: async (req: Request) => await this.handleListTasks(req),
POST: async (req: Request) => await this.handleCreateTask(req), POST: async (req: Request) => await this.handleCreateTask(req),
}, },
"/api/tasks/reorder": {
POST: async (req: Request) => await this.handleReorderTask(req),
},
"/api/tasks/cleanup": {
GET: async (req: Request) => await this.handleCleanupPreview(req),
},
"/api/tasks/cleanup/execute": {
POST: async (req: Request) => await this.handleCleanupExecute(req),
},
"/api/task/:id": { "/api/task/:id": {
GET: async (req: Request & { params: { id: string } }) => await this.handleGetTask(req.params.id), GET: async (req: Request & { params: { id: string } }) => await this.handleGetTask(req.params.id),
}, },
@ -218,15 +228,6 @@ export class BacklogServer {
"/api/drafts/:id/promote": { "/api/drafts/:id/promote": {
POST: async (req: Request & { params: { id: string } }) => await this.handlePromoteDraft(req.params.id), POST: async (req: Request & { params: { id: string } }) => await this.handlePromoteDraft(req.params.id),
}, },
"/api/tasks/reorder": {
POST: async (req: Request) => await this.handleReorderTask(req),
},
"/api/tasks/cleanup": {
GET: async (req: Request) => await this.handleCleanupPreview(req),
},
"/api/tasks/cleanup/execute": {
POST: async (req: Request) => await this.handleCleanupExecute(req),
},
"/api/version": { "/api/version": {
GET: async () => await this.handleGetVersion(), GET: async () => await this.handleGetVersion(),
}, },