This commit is contained in:
Giancarmine Salucci
2025-12-21 02:03:05 +01:00
parent 167cd1f4bb
commit 9357bd483a
36 changed files with 6251 additions and 1547 deletions

32
src/hooks.server.ts Normal file
View File

@@ -0,0 +1,32 @@
import { startScheduler, stopScheduler } from '$lib/server/scheduler';
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_HOURS: Hours between each renewal (default: 12)
*/
export const init: ServerInit = async () => {
console.log('[Server Init] Starting SvelteKit server...');
// Start the authentication scheduler
// 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');
});