Add proof-of-work challenge, session hub support, and status metrics across backend and frontend apps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OverlordandClaude Bot committed 2026-10-13 11:43:49 +02:00
1 parent b841c2d1f6
commit 9647ac8c50
29 files changed
+1492 -292

No files matched your search

+45 -17
View File
@@ -1,30 +1,58 @@
export type BackendConfig = {
host: string;
port: number;
spawnerSocket: string;
frontendDir: string;
host: string;
port: number;
/** Port of the metrics endpoint; 0 disables it. Only published to the host's loopback. */
metricsPort: number;
spawnerSocket: string;
frontendDir: string;
/** Directory for the status file shown in sandboxes; empty disables it. */
statusDir: string;
build: string;
/** Exact origins allowed to open terminal sessions. Empty allows every origin. */
allowedOrigins: string[];
sessionSeconds: number;
outputRate: number;
allowedOrigins: string[];
maxSessions: number;
maxQueue: number;
powDifficulty: number;
sessionSeconds: number;
idleSeconds: number;
idleWarningSeconds: number;
graceSeconds: number;
outputRate: number;
};
function integer(env: NodeJS.ProcessEnv, name: string, fallback: number): number
function integer(env: NodeJS.ProcessEnv, name: string, fallback: number, minimum = 1): number
{
const value = Number(env[name] ?? fallback);
if (!Number.isInteger(value) || value < 1) throw new Error(`${name} must be a positive integer`);
if (!Number.isInteger(value) || value < minimum) throw new Error(`${name} must be an integer of at least ${minimum}`);
return value;
}
function list(value: string | undefined): string[] {
return (value ?? '').split(',').map((entry) => entry.trim()).filter(Boolean);
}
export function loadConfig(env: NodeJS.ProcessEnv): BackendConfig
{
return {
host: env.HOST ?? '0.0.0.0',
port: integer(env, 'PORT', 8080),
spawnerSocket: env.SPAWNER_SOCKET ?? '/run/spawner/spawner.sock',
frontendDir: env.FRONTEND_DIR ?? '/app/public',
allowedOrigins: (env.ALLOWED_ORIGINS ?? '').split(',').map((origin) => origin.trim()).filter(Boolean),
sessionSeconds: integer(env, 'SESSION_SECONDS', 20 * 60),
outputRate: integer(env, 'OUTPUT_BYTES_PER_SECOND', 1024 * 1024),
const config: BackendConfig = {
host: env.HOST ?? '0.0.0.0',
port: integer(env, 'PORT', 8080),
metricsPort: integer(env, 'METRICS_PORT', 9090, 0),
spawnerSocket: env.SPAWNER_SOCKET ?? '/run/spawner/spawner.sock',
frontendDir: env.FRONTEND_DIR ?? '/app/public',
statusDir: env.STATUS_DIR ?? '',
build: env.BUILD_SHA ?? 'dev',
allowedOrigins: list(env.ALLOWED_ORIGINS),
maxSessions: integer(env, 'MAX_SESSIONS', 12),
maxQueue: integer(env, 'MAX_QUEUE', 20, 0),
powDifficulty: integer(env, 'POW_DIFFICULTY', 20, 0),
sessionSeconds: integer(env, 'SESSION_SECONDS', 20 * 60),
idleSeconds: integer(env, 'IDLE_SECONDS', 180),
idleWarningSeconds: integer(env, 'IDLE_WARNING_SECONDS', 30),
graceSeconds: integer(env, 'GRACE_SECONDS', 45),
outputRate: integer(env, 'OUTPUT_BYTES_PER_SECOND', 1024 * 1024),
};
if (config.idleWarningSeconds >= config.idleSeconds) throw new Error('IDLE_WARNING_SECONDS must be below IDLE_SECONDS');
if (config.powDifficulty > 28) throw new Error('POW_DIFFICULTY above 28 would take phones minutes');
return config;
}