feat(HAI-001): add rate limiting middleware to API endpoints

This commit is contained in:
Dustin Byrne
2026-03-25 20:15:11 -04:00
parent e142e049d3
commit a1397d9eb7
3 changed files with 92 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
import type { TaskStore, MergeResult } from "@hai/core";
import { createApiRoutes } from "./routes.js";
import { createSSE } from "./sse.js";
import { rateLimit, RATE_LIMITS } from "./rate-limit.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -28,8 +29,11 @@ export function createServer(store: TaskStore, options?: ServerOptions) {
app.use(express.static(clientDir));
// SSE endpoint
app.get("/api/events", createSSE(store));
// Rate limiting — stricter limit on SSE connections
app.get("/api/events", rateLimit(RATE_LIMITS.sse), createSSE(store));
// Rate limiting — mutation endpoints (POST/PUT/PATCH/DELETE)
app.use("/api", rateLimit(RATE_LIMITS.api));
// REST API
app.use("/api", createApiRoutes(store, options));