forked from StarkMindsHQ/StrellerMinds-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
55 lines (48 loc) · 1.55 KB
/
server.ts
File metadata and controls
55 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Standalone WebSocket server for real-time collaboration
* Run this with: npx tsx server.ts
* Or compile and run: npm run dev:server
*/
import http from 'http';
import { createCollaborationServer } from './src/lib/collaboration/server';
const PORT = process.env.WS_PORT || 3001;
const app = http.createServer();
// Create server (now async due to Redis connection)
(async () => {
try {
await createCollaborationServer(app);
console.log('✅ Collaboration server initialized');
app.listen(PORT, () => {
console.log(`Collaboration WebSocket server running on port ${PORT}`);
console.log(
`Connect from: ${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}`,
);
if (process.env.REDIS_URL) {
console.log('✅ Using Redis for session storage');
} else {
console.log('📦 Using in-memory storage (Redis not configured)');
}
});
} catch (error) {
console.error('❌ Failed to initialize collaboration server:', error);
process.exit(1);
}
})();
// Graceful shutdown
import { cleanupCollaborationServer } from './src/lib/collaboration/server';
process.on('SIGTERM', async () => {
console.log('SIGTERM received, shutting down gracefully');
await cleanupCollaborationServer();
app.close(() => {
console.log('Server closed');
process.exit(0);
});
});
process.on('SIGINT', async () => {
console.log('SIGINT received, shutting down gracefully');
await cleanupCollaborationServer();
app.close(() => {
console.log('Server closed');
process.exit(0);
});
});