50 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/**
 | 
						|
 * Phase 3 Startup Configuration
 | 
						|
 * 
 | 
						|
 * Add these lines to server/index.mjs before app.listen():
 | 
						|
 * 
 | 
						|
 * 1. Setup performance endpoint
 | 
						|
 * 2. Setup deferred Meilisearch indexing
 | 
						|
 * 3. Start server with monitoring
 | 
						|
 */
 | 
						|
 | 
						|
// ============================================================================
 | 
						|
// BEFORE app.listen() - Add these lines:
 | 
						|
// ============================================================================
 | 
						|
 | 
						|
// Setup performance monitoring endpoint
 | 
						|
setupPerformanceEndpoint(app, performanceMonitor, metadataCache, meilisearchCircuitBreaker);
 | 
						|
 | 
						|
// Setup deferred Meilisearch indexing (non-blocking)
 | 
						|
const { scheduleIndexing } = await setupDeferredIndexing(vaultDir, fullReindex);
 | 
						|
 | 
						|
// Start server
 | 
						|
const server = app.listen(PORT, '0.0.0.0', () => {
 | 
						|
  console.log(`🚀 ObsiViewer server running on http://0.0.0.0:${PORT}`);
 | 
						|
  console.log(`📁 Vault directory: ${vaultDir}`);
 | 
						|
  console.log(`📊 Performance monitoring: http://0.0.0.0:${PORT}/__perf`);
 | 
						|
  
 | 
						|
  // Schedule background indexing (non-blocking)
 | 
						|
  scheduleIndexing();
 | 
						|
  console.log('✅ Server ready - Meilisearch indexing in background');
 | 
						|
});
 | 
						|
 | 
						|
// Graceful shutdown
 | 
						|
process.on('SIGINT', () => {
 | 
						|
  console.log('\n🛑 Shutting down server...');
 | 
						|
  server.close(() => {
 | 
						|
    console.log('✅ Server shutdown complete');
 | 
						|
    process.exit(0);
 | 
						|
  });
 | 
						|
});
 | 
						|
 | 
						|
// ============================================================================
 | 
						|
// NOTES:
 | 
						|
// ============================================================================
 | 
						|
// - The server starts immediately without waiting for Meilisearch indexing
 | 
						|
// - Indexing happens in the background via setImmediate()
 | 
						|
// - If indexing fails, it retries after 5 minutes
 | 
						|
// - Performance metrics available at /__perf endpoint
 | 
						|
// - Cache hit rate should reach > 80% after 5 minutes of usage
 | 
						|
// - Circuit breaker protects against cascading failures
 |