Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (42 loc) · 1.44 KB
/
Copy pathserver.js
File metadata and controls
48 lines (42 loc) · 1.44 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
const { createServer } = require('http');
const { parse } = require('url');
const next = require('next');
const fetch = require('node-fetch'); // Using regular import without node: prefix
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = createServer((req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
});
server.listen(3000, (err) => {
if (err) throw err;
console.log('> Ready on http://localhost:3000');
// Initialize email monitoring service after server starts
console.log('Initializing email monitoring service...');
setTimeout(() => {
fetch('http://localhost:3000/api/email-monitor/init', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
console.log('Email monitoring service initialized:', data);
})
.catch(error => {
console.error('Error initializing email monitoring service:', error);
});
}, 3000); // Wait 3 seconds for server to fully initialize
});
// Handle graceful shutdown
const handleShutdown = () => {
console.log('Server shutting down...');
process.exit(0);
};
// Listen for termination signals
process.on('SIGINT', handleShutdown);
process.on('SIGTERM', handleShutdown);
});