Add parallel HTTPS server support - #84
Conversation
When SSL_KEY and SSL_CERT env vars point to valid certificate files, an HTTPS server starts alongside the always-on HTTP server on HTTPS_PORT (default 1338). Socket.IO attaches to both servers via ServerServiceProvider. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Too much diff to scan? Review this PR in Change Stack to start with the highest-impact changes. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds optional HTTPS server support with environment-driven SSL configuration, shared CORS options, and conditional Socket.IO attachment; also introduces a typed IntervalTimeoutError and special-cases it in error logging. ChangesHTTPS Server Support
Interval Timeout Error Handling
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/index.ts (1)
181-185: ⚖️ Poor tradeoffConsider adding error handling for listen failures.
While Node.js will throw by default if the port is unavailable, explicitly handling listen errors would provide better diagnostics and graceful degradation.
♻️ Optional improvement to add error handler
if (httpsServer !== undefined) { - httpsServer.listen(APP_HTTPS_PORT, () => { + httpsServer.listen(APP_HTTPS_PORT, () => { logger.info(`SlvCtrl+ server listening on https://localhost:${APP_HTTPS_PORT} (ssl)`); + }).on('error', (err: Error) => { + logger.error(`HTTPS server failed to start: ${err.message}`, err); }); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/index.ts` around lines 181 - 185, The httpsServer.listen call lacks an explicit 'error' handler for startup failures; attach a listener on httpsServer for the 'error' event (or pass an error-first callback to listen) to catch bind errors and log them via logger.error including APP_HTTPS_PORT and the error, and optionally perform graceful shutdown/exit; update the block around httpsServer.listen/httpsServer to add this error handling referencing httpsServer, listen, APP_HTTPS_PORT, and logger.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/index.ts`:
- Around line 49-51: The current creation of httpsServer uses
fs.readFileSync(SSL_KEY_FILE) and fs.readFileSync(SSL_CERT_FILE) directly which
can throw and crash startup; wrap the file reads in a try-catch around the
https.createServer call (or a small helper) so that if reading SSL_KEY_FILE or
SSL_CERT_FILE fails you log a clear error (including the file path and error
message) via your logger and either fallback to undefined for httpsServer or
call process.exit(1); update the code that constructs httpsServer (the
https.createServer(...) invocation and any surrounding logic referencing
SSL_KEY_FILE/SSL_CERT_FILE) to use the try-catch and safe behavior.
In `@src/serviceProvider/serverServiceProvider.ts`:
- Around line 18-23: The Socket.IO server is configured with origin: '*' which
bypasses ALLOWED_ORIGINS; update the Server(...) CORS option in the socket
initialization (the Server constructor call) to use the same origin callback
logic as Express (e.g., a corsOriginCallback function that checks
ALLOWED_ORIGINS.includes(origin) and allows undefined/or empty list), and ensure
ALLOWED_ORIGINS or that corsOriginCallback is passed into or imported by
serverServiceProvider so the Server CORS uses the shared corsOriginCallback
instead of '*' to enforce the same origin restrictions.
---
Nitpick comments:
In `@src/index.ts`:
- Around line 181-185: The httpsServer.listen call lacks an explicit 'error'
handler for startup failures; attach a listener on httpsServer for the 'error'
event (or pass an error-first callback to listen) to catch bind errors and log
them via logger.error including APP_HTTPS_PORT and the error, and optionally
perform graceful shutdown/exit; update the block around
httpsServer.listen/httpsServer to add this error handling referencing
httpsServer, listen, APP_HTTPS_PORT, and logger.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 985b4539-646b-4502-b1c2-7cd520adebd4
📒 Files selected for processing (5)
.env.examplesrc/index.tssrc/serviceProvider/serverServiceProvider.tssrc/util/async.tssrc/util/error.ts
|
@coderabbitai rate limit |
|
Your plan includes 1 PR review per hour. More reviews will be available in 2 minutes and 34 seconds. |
|
@coderabbitai review please |
|
✅ Action performedReview finished.
|
When SSL_KEY and SSL_CERT env vars point to valid certificate files, an HTTPS server starts alongside the always-on HTTP server on HTTPS_PORT (default 1338). Socket.IO attaches to both servers via ServerServiceProvider.
Summary by CodeRabbit
New Features
Refactor
Chores