mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 18:30:39 +09:00
Add API server with routes, services, and middleware
Express server with CRUD routes for agents, goals, issues, projects, and activity log. Includes validation middleware, structured error handling, request logging, and health check endpoint with tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
948e8e8c94
commit
c9d7cbfe44
24 changed files with 624 additions and 0 deletions
42
server/src/app.ts
Normal file
42
server/src/app.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import express, { Router } from "express";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import type { Db } from "@paperclip/db";
|
||||
import { httpLogger, errorHandler } from "./middleware/index.js";
|
||||
import { healthRoutes } from "./routes/health.js";
|
||||
import { agentRoutes } from "./routes/agents.js";
|
||||
import { projectRoutes } from "./routes/projects.js";
|
||||
import { issueRoutes } from "./routes/issues.js";
|
||||
import { goalRoutes } from "./routes/goals.js";
|
||||
import { activityRoutes } from "./routes/activity.js";
|
||||
|
||||
export function createApp(db: Db, opts: { serveUi: boolean }) {
|
||||
const app = express();
|
||||
|
||||
app.use(express.json());
|
||||
app.use(httpLogger);
|
||||
|
||||
// Mount API routes
|
||||
const api = Router();
|
||||
api.use("/health", healthRoutes());
|
||||
api.use("/agents", agentRoutes(db));
|
||||
api.use("/projects", projectRoutes(db));
|
||||
api.use("/issues", issueRoutes(db));
|
||||
api.use("/goals", goalRoutes(db));
|
||||
api.use("/activity", activityRoutes(db));
|
||||
app.use("/api", api);
|
||||
|
||||
// SPA fallback for serving the UI build
|
||||
if (opts.serveUi) {
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const uiDist = path.resolve(__dirname, "../../ui/dist");
|
||||
app.use(express.static(uiDist));
|
||||
app.get("*", (_req, res) => {
|
||||
res.sendFile(path.join(uiDist, "index.html"));
|
||||
});
|
||||
}
|
||||
|
||||
app.use(errorHandler);
|
||||
|
||||
return app;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue