diff --git a/index.js b/index.js index 829265e..68f18fb 100644 --- a/index.js +++ b/index.js @@ -58,20 +58,36 @@ if (cluster.isMaster) { // startExpress(); function startExpress() { - // var server = http.createServer(app); - // sticky.listen(server, PORT); + // app.listen(PORT, () => { // winston.logger.info( - // `Server is running with sticky session on version ${ + // `Server is running on version ${ // process.env.VERSION // } environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} ` // ); - // } else { - app.listen(PORT, () => { - winston.logger.info( - `Server is running on version ${ - process.env.VERSION - } environment: ${process.env.NODE_ENV.toUpperCase()} port: ${PORT} on ${serverActive}. HSM STATUS : ${serverHSMStatus} ` + // }); + + const server = app.listen(PORT, () => { + console.log( + `Worker ${process.pid} started. Listening on port ${ + server.address().port + }` ); }); - // } + + // Use sticky-session with the server instance + sticky.listen(server); } + +// Use sticky-session to handle sticky sessions +// if (!sticky.listen(cluster, port)) { +// // This is the master process, and it should not be listening to the port +// cluster.on('listening', (worker, address) => { +// console.log( +// `Worker ${worker.id} is now connected to ${address.address}:${address.port}` +// ); +// }); + +// cluster.on('exit', (worker) => { +// console.log(`Worker ${worker.id} has exited`); +// }); +// }