Files
insta-recipe/src/hooks.server.ts
Giancarmine Salucci 93aa25a31c fix: resolve critical app functionality issues
Complete implementation of fixes for queue processing, SSE connection display, service worker installation, and failing tests.

Key Changes:
- Fix queue processor startup with proper import and subscription mechanism
- Implement centralized API error handling middleware for proper HTTP status codes
- Enhance service worker configuration for PWA compliance and reliability
- Fix SSE connection display with reactive state management
- Add comprehensive test coverage and health check endpoints

Results:
- All 169 tests now passing (previously 16 failing)
- Queue items process immediately from pending to success/error states
- Real-time SSE connection status with auto-reconnection logic
- Proper PWA functionality with working service worker registration
- API endpoints return correct HTTP status codes (400/404/409) instead of 500 errors

This resolves the critical issues preventing core app functionality and enables proper production deployment.
2025-12-22 04:27:59 +01:00

33 lines
1.2 KiB
TypeScript

import { startScheduler, stopScheduler } from '$lib/server/scheduler';
import '$lib/server/queue/QueueProcessor'; // Trigger QueueProcessor auto-start
import type { ServerInit } from '@sveltejs/kit';
/**
* Initialize server-wide functionality
* Runs once when the server starts
*
* Environment variables:
* - AUTH_SCHEDULER_ENABLED: Set to 'true' to enable periodic auth renewal
* - AUTH_SCHEDULER_INTERVAL_MINUTES: Minutes between each renewal (default: 720)
*/
export const init: ServerInit = async () => {
console.log('[Server Init] Starting SvelteKit server...');
console.log('[Server Init] QueueProcessor auto-started via import');
// The scheduler will renew the Instagram session by loading the existing auth.json
// and refreshing it with Instagram (requires initial setup via gen-auth.js)
await startScheduler();
};
/**
* Listen for graceful shutdown
* Clean up resources when the server is shutting down
*/
process.on('sveltekit:shutdown', async (reason) => {
console.log(`[Server Shutdown] Shutdown triggered by: ${reason}`);
// Stop the scheduler gracefully
await stopScheduler();
console.log('[Server Shutdown] Cleanup complete');
});