-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
78 lines (68 loc) · 3.15 KB
/
Copy pathindex.ts
File metadata and controls
78 lines (68 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import 'dotenv/config';
import express from 'express';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { registerPullRequestsRoutes } from '@asucregonzalez/section-pull-requests/server';
import { registerTasksRoutes } from '@asucregonzalez/section-tasks/server';
import { registerJournalRoutes } from '@asucregonzalez/section-journal/server';
import { registerMeetingsRoutes } from '@asucregonzalez/section-meetings/server';
import { registerClaudeSessionsRoutes } from '@asucregonzalez/section-claude-sessions/server';
/**
* The API server. Each installed section with a backend gets its own router and a
* SectionContext telling it where your content and its state live.
*
* To add a section's API: import its `register…Routes` and mount it the same way.
*/
const PORT = Number(process.env.PORT ?? 4320);
const app = express();
app.use(express.json({ limit: '1mb' }));
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.resolve(__dirname, '..');
const DIST = path.join(ROOT, 'dist');
const ctx = {
// Your markdown workspace: tasks/active.md, tasks/journal.md, meetings/*.md,
// team/task-labels.json. Defaults to the content/ folder in this repo — set
// CONTENT_ROOT to point at your own notes folder instead.
contentRoot: process.env.CONTENT_ROOT
? path.resolve(process.env.CONTENT_ROOT)
: path.join(ROOT, 'content'),
// Section runtime state (PR projects, squads, saved checkpoints). Gitignored.
dataDir: path.join(ROOT, '.data'),
env: process.env,
gwsConfigDir: process.env.GOOGLE_WORKSPACE_CLI_CONFIG_DIR ?? '',
};
// Identity, not just liveness. `start-stack.sh` used to accept any server that
// answered on the API port — so with another Command Center already on 4320 it
// reported "the stack is up" while THIS server had died with EADDRINUSE, and the
// dashboard silently rendered the other workspace's tasks. Returning contentRoot
// lets the caller check it reached the right app.
app.get('/api/health', (_req, res) => {
res.json({ ok: true, app: 'command-center', contentRoot: ctx.contentRoot, pid: process.pid });
});
console.log(`[command-center] content root: ${ctx.contentRoot}`);
// --- sections ---------------------------------------------------------------
// Pull requests starts with no projects; add your squads from its own UI. To
// pre-seed them in code, pass { seedProjects, seedSquads, displayNames } as a
// third argument — written to .data on first run only.
const routers = [
registerPullRequestsRoutes,
registerTasksRoutes,
registerJournalRoutes,
registerMeetingsRoutes,
// Reads ~/.claude/sessions and ~/.claude/projects — nothing in this repo. It
// reports no sessions rather than failing when those are absent or unreadable.
registerClaudeSessionsRoutes,
];
for (const register of routers) {
const router = express.Router();
register(router, ctx);
app.use(router);
}
// Serve the built SPA in production (`pnpm build && pnpm start`).
app.use(express.static(DIST));
app.get(/^(?!\/api\/).*/, (_req, res) => {
res.sendFile(path.join(DIST, 'index.html'));
});
app.listen(PORT, () => {
console.log(`[command-center] http://localhost:${PORT}`);
});