mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 22:02:08 +03:00
Phase 5 — Foundation & Security: - SQLite domain state persistence (5 tables, 4 modules: fallback, budget, lockout, circuit breaker) - Write-through cache pattern for state survival across restarts - Race condition fix in route.js (Promise-based singleton) - Default password hardening (.env.example) - Server init error handling improvement Phase 6 — Architecture Refactoring: - OAuth providers extracted into 12 individual modules (providers.js 1051→144 lines) - Policy Engine (lockout→budget→fallback) with evaluateRequest/evaluateFirstAllowed - Deterministic round-robin via persistent counter Map - Telemetry window fix with proper recordedAt timestamps - Proxy decoupled from API settings (direct import vs HTTP self-fetch) Tests: 295 pass (22 new: domain-persistence 16, policy-engine 6) Docs: CHANGELOG, README, ARCHITECTURE.md updated
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
// Server startup script
|
|
import initializeCloudSync from "./shared/services/initializeCloudSync.js";
|
|
import { enforceSecrets } from "./shared/utils/secretsValidator.js";
|
|
import { initAuditLog, cleanupExpiredLogs, logAuditEvent } from "./lib/compliance/index.js";
|
|
|
|
async function startServer() {
|
|
// FASE-01: Validate required secrets before anything else (fail-fast)
|
|
enforceSecrets();
|
|
|
|
// Compliance: Initialize audit_log table
|
|
try {
|
|
initAuditLog();
|
|
console.log("[COMPLIANCE] Audit log table initialized");
|
|
} catch (err) {
|
|
console.warn("[COMPLIANCE] Could not initialize audit log:", err.message);
|
|
}
|
|
|
|
// Compliance: One-time cleanup of expired logs
|
|
try {
|
|
const cleanup = cleanupExpiredLogs();
|
|
if (cleanup.deletedUsage || cleanup.deletedCallLogs || cleanup.deletedAuditLogs) {
|
|
console.log("[COMPLIANCE] Expired log cleanup:", cleanup);
|
|
}
|
|
} catch (err) {
|
|
console.warn("[COMPLIANCE] Log cleanup failed:", err.message);
|
|
}
|
|
|
|
console.log("Starting server with cloud sync...");
|
|
|
|
try {
|
|
// Initialize cloud sync
|
|
await initializeCloudSync();
|
|
console.log("Server started with cloud sync initialized");
|
|
|
|
// Log server start event to audit log
|
|
logAuditEvent({ action: "server.start", details: { timestamp: new Date().toISOString() } });
|
|
} catch (error) {
|
|
console.error("[FATAL] Error initializing cloud sync:", error);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Start the server initialization
|
|
startServer().catch((err) => {
|
|
console.error("[FATAL] Server initialization failed:", err);
|
|
process.exit(1);
|
|
});
|
|
|
|
// Export for use as module if needed
|
|
export default startServer;
|