ADR-022 - websocket notificaitons - also more test fixes with stores
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 18m47s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 18m47s
This commit is contained in:
21
server.ts
21
server.ts
@@ -40,6 +40,7 @@ import reactionsRouter from './src/routes/reactions.routes';
|
||||
import storeRouter from './src/routes/store.routes';
|
||||
import { errorHandler } from './src/middleware/errorHandler';
|
||||
import { backgroundJobService, startBackgroundJobs } from './src/services/backgroundJobService';
|
||||
import { websocketService } from './src/services/websocketService.server';
|
||||
import type { UserProfile } from './src/types';
|
||||
|
||||
// API Documentation (ADR-018)
|
||||
@@ -315,13 +316,17 @@ app.use(errorHandler);
|
||||
// This prevents the server from trying to listen on a port during tests.
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
const PORT = process.env.PORT || 3001;
|
||||
app.listen(PORT, () => {
|
||||
const server = app.listen(PORT, () => {
|
||||
logger.info(`Authentication server started on port ${PORT}`);
|
||||
console.log('--- REGISTERED API ROUTES ---');
|
||||
console.table(listEndpoints(app));
|
||||
console.log('-----------------------------');
|
||||
});
|
||||
|
||||
// Initialize WebSocket server (ADR-022)
|
||||
websocketService.initialize(server);
|
||||
logger.info('WebSocket server initialized for real-time notifications');
|
||||
|
||||
// Start the scheduled background jobs
|
||||
startBackgroundJobs(
|
||||
backgroundJobService,
|
||||
@@ -332,8 +337,18 @@ if (process.env.NODE_ENV !== 'test') {
|
||||
);
|
||||
|
||||
// --- Graceful Shutdown Handling ---
|
||||
process.on('SIGINT', () => gracefulShutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
|
||||
const handleShutdown = (signal: string) => {
|
||||
logger.info(`${signal} received, starting graceful shutdown...`);
|
||||
|
||||
// Shutdown WebSocket server
|
||||
websocketService.shutdown();
|
||||
|
||||
// Shutdown queues and workers
|
||||
gracefulShutdown(signal);
|
||||
};
|
||||
|
||||
process.on('SIGINT', () => handleShutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => handleShutdown('SIGTERM'));
|
||||
}
|
||||
|
||||
// Export the app for integration testing
|
||||
|
||||
Reference in New Issue
Block a user