Skip to content

Commit 3008fb0

Browse files
committed
fix: refactor HTTPS server creation to improve error handling and readability
1 parent 4b29bd5 commit 3008fb0

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

server/app.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,25 @@ app.get("/api/health", (req, res) => {
4848
});
4949

5050
if (process.env.NODE_ENV === 'production') {
51-
https.createServer({
51+
const server = https.createServer({
5252
key: fs.readFileSync(process.env.SSL_KEY_PATH),
5353
cert: fs.readFileSync(process.env.SSL_CERT_PATH)
54-
}, app).listen(process.env.HTTPS_PORT, () => {
55-
console.log(`API is running on: http://localhost:${process.env.HTTPS_PORT}`);
54+
}, app);
55+
// this
56+
server.on('tlsClientError', (err, tlsSocket) => {
57+
console.error('TLS Client Error:', err);
58+
});
59+
60+
server.on('clientError', (err, socket) => {
61+
console.error('Client Error:', err);
62+
});
63+
64+
server.on('error', (err) => {
65+
console.error('Server Error:', err);
66+
});
67+
//comment above
68+
server.listen(process.env.HTTPS_PORT, () => {
69+
console.log(`API is running on PORT: ${process.env.HTTPS_PORT}`);
5670
});
5771
} else {
5872
app.listen(PORT, () => {

0 commit comments

Comments
 (0)