Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import express from 'express';
import cors from 'cors';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
import { createServer } from 'http';
import { WebSocketManager } from './websocket.js';
import { ActivityStore } from './activity-store.js';
import { getHotFolders, clearCache as clearGitCache } from './git-activity.js';
import { FileActivityEvent, ThinkingEvent, AgentThinkingState } from './types.js';

const PORT = 5174; // Fixed port - never change
const PORT = parseInt(process.env.PORT || '5174', 10);

// PROJECT_ROOT: Use env var, command line arg, or detect from cwd
// If running from server/ subdirectory, go up to find the actual project root
Expand Down Expand Up @@ -70,8 +71,8 @@ const SERVER_START_TIME = Date.now();
const recentActivityBuffer: Array<{ type: string; filePath: string; agentId?: string; timestamp: number }> = [];
const MAX_ACTIVITY_BUFFER = 50;

// Agent state persistence
const STATE_FILE = path.join(PROJECT_ROOT, '.codemap-state.json');
// Agent state persistence — configurable to avoid writing into the watched project
const STATE_FILE = process.env.CODEMAP_STATE_FILE || path.join(PROJECT_ROOT, '.codemap-state.json');

function saveAgentState(): void {
try {
Expand Down Expand Up @@ -505,6 +506,16 @@ app.post('/api/git-commit', async (_req, res) => {
}
});

// Serve client build in production (Express serves everything from one port)
const clientDist = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../client/dist');
if (fs.existsSync(clientDist)) {
app.use(express.static(clientDist));
// Catch-all for React Router (/, /hotel)
app.get('*', (_req, res) => {
res.sendFile(path.join(clientDist, 'index.html'));
});
}

// Load persisted state before starting server
loadAgentState();

Expand Down