| |
| import initializeCloudSync from "./shared/services/initializeCloudSync"; |
| import { enforceSecrets } from "./shared/utils/secretsValidator"; |
| import { initAuditLog, cleanupExpiredLogs, logAuditEvent } from "./lib/compliance/index"; |
| import { initConsoleInterceptor } from "./lib/consoleInterceptor"; |
|
|
| async function startServer() { |
| |
| await import("./lib/usage/migrations"); |
|
|
| |
| initConsoleInterceptor(); |
|
|
| |
| enforceSecrets(); |
|
|
| |
| try { |
| initAuditLog(); |
| console.log("[COMPLIANCE] Audit log table initialized"); |
| } catch (err) { |
| console.warn("[COMPLIANCE] Could not initialize audit log:", err.message); |
| } |
|
|
| |
| try { |
| const cleanup = cleanupExpiredLogs(); |
| if ( |
| cleanup.deletedUsage || |
| cleanup.deletedCallLogs || |
| cleanup.deletedProxyLogs || |
| cleanup.deletedRequestDetailLogs || |
| cleanup.deletedAuditLogs || |
| cleanup.deletedMcpAuditLogs |
| ) { |
| 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 { |
| |
| await initializeCloudSync(); |
| console.log("Server started with cloud sync initialized"); |
|
|
| |
| logAuditEvent({ action: "server.start", details: { timestamp: new Date().toISOString() } }); |
| } catch (error) { |
| console.error("[FATAL] Error initializing cloud sync:", error); |
| process.exit(1); |
| } |
|
|
| |
| if (process.env.PRICING_SYNC_ENABLED === "true") { |
| try { |
| const { initPricingSync } = await import("./lib/pricingSync"); |
| await initPricingSync(); |
| } catch (err) { |
| console.warn( |
| "[PRICING_SYNC] Could not initialize:", |
| err instanceof Error ? err.message : err |
| ); |
| } |
| } |
| } |
|
|
| |
| startServer().catch((err) => { |
| console.error("[FATAL] Server initialization failed:", err); |
| process.exit(1); |
| }); |
|
|
| |
| export default startServer; |
|
|