add-api-route
Scaffold a new API route with proper auth, workspace scoping, and middleware chain for the Mako Hono backend. Use when adding new API endpoints.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scaffold a new API route with proper auth, workspace scoping, and middleware chain for the Mako Hono backend. Use when adding new API endpoints.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Load when building, editing, or debugging Mako React apps — app files, npm dependencies, data bindings, the @mako/app-sdk hooks (useQuery / useDuckDB / useLocation / useSearchParams / navigate), URL state and shareable deep links, materialized Parquet/DuckDB bindings, and the live preview runtime.
Load for dbt branches, commits, pushes, pull requests, merges, repository sync, or branch cleanup.
Load when creating, editing, scheduling, running, or debugging dbt jobs and production deployments.
Load when building, editing, running, or debugging dbt models, dbt projects, schema.yml tests, sources, seeds, snapshots, incremental models, materializations, or dbt jobs in the Transforms section.
Load when creating, editing, configuring, validating, or debugging database sync flows, connector flows, pagination, incremental sync, destination mappings, and flow form fields.
Add a new MCP server preset (connector) to Mako's MCP client system — server URL, auth model (OAuth DCR, pre-registered app, or API key), scopes, icon, tests, and docs. Use when connecting a new external MCP server (like Slack or Close CRM) or changing how MCP connections authenticate.
| name | add-api-route |
| description | Scaffold a new API route with proper auth, workspace scoping, and middleware chain for the Mako Hono backend. Use when adding new API endpoints. |
API routes use Hono, follow a strict middleware ordering, and delegate business logic to the service layer.
Create api/src/routes/<feature>.ts:
import { Hono } from "hono";
import { unifiedAuthMiddleware } from "../auth/unified-auth.middleware";
import { loggers, enrichContextWithWorkspace } from "../logging";
import { workspaceService } from "../services/workspace.service";
const log = loggers.api("<feature>");
const routes = new Hono();
// Apply auth middleware to all routes
routes.use("*", unifiedAuthMiddleware);
// Workspace verification with defense-in-depth
routes.use("/:workspaceId/*", async (c, next) => {
const workspaceId = c.req.param("workspaceId");
const user = c.get("user");
const workspace = c.get("workspace");
if (workspace) {
if (workspace._id.toString() !== workspaceId) {
return c.json(
{ error: "API key not authorized for this workspace" },
403,
);
}
} else if (user) {
const hasAccess = await workspaceService.hasAccess(workspaceId, user.id);
if (!hasAccess) {
return c.json({ error: "Access denied to workspace" }, 403);
}
} else {
// CRITICAL: Defense in depth — reject if neither auth type succeeded
return c.json({ error: "Unauthorized" }, 401);
}
enrichContextWithWorkspace(workspaceId);
await next();
});
// Route handlers
routes.get("/:workspaceId/items", async c => {
const workspaceId = c.req.param("workspaceId");
try {
// Delegate to service layer
const result = await myService.getItems(workspaceId);
return c.json({ data: result });
} catch (error) {
log.error("Failed to get items", { error, workspaceId });
return c.json({ error: "Internal server error" }, 500);
}
});
export default routes;
Edit api/src/index.ts:
import featureRoutes from "./routes/<feature>";
app.route("/api/<feature>", featureRoutes);
Create api/src/services/<feature>.service.ts with business logic. Routes should be thin — parameter parsing, auth, and delegating to services.
pnpm devunifiedAuthMiddleware → workspace verification (with else clause) → route handler
else clause in workspace verification for defense in depth.loggers.api("<feature>") for route-specific logging. Never console.log.enrichContextWithWorkspace() only AFTER authorization succeeds.api/src/auth/unified-auth.middleware.ts.cursor/rules/30-auth.mdc.cursor/rules/20-api-routing.mdcapi/src/routes/consoles.ts