-
Notifications
You must be signed in to change notification settings - Fork 780
feat: add optional SSL/TLS support for HTTPS #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add support for running the server with HTTPS by configuring SSL_CERT and SSL_KEY environment variables. When both variables are set and the certificate files exist, the server automatically uses HTTPS instead of HTTP. This enables secure connections for deployments that require encryption, while maintaining full backward compatibility (HTTP remains the default). Co-Authored-By: Claude Opus 4.5 <[email protected]>
WalkthroughAdds optional HTTPS support: Changes
Sequence Diagram(s)sequenceDiagram
participant Env as "Environment"
participant FS as "Filesystem"
participant Server as "Node process"
participant Client as "Client / Browser"
participant WS as "WebSocket"
Env->>Server: Provide PORT, SSL_PORT, SSL_CERT, SSL_KEY
Server->>FS: Check existence of SSL_CERT & SSL_KEY
alt both files exist
Server->>Server: create HTTPS server (https.createServer)
Server->>WS: attach WebSocket to HTTPS server
Server->>Server: listen on SSL_PORT or PORT
else missing/invalid
Server->>Server: create HTTP server (http.createServer)
Server->>WS: attach WebSocket to HTTP server
Server->>Server: listen on PORT
end
Server->>Client: Log protocol-aware URL (http(s)://host:port)
Client->>Server: Connect via http(s)
Client->>WS: Establish WebSocket over same server
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@server/index.js`:
- Around line 1844-1845: The log currently derives protocol from
SSL_CERT/SSL_KEY which can be wrong if TLS setup fails; change the console.log
that prints Server URL to use the actual runtime flag `useHttps` (the boolean
produced by your server creation logic) instead of checking SSL_CERT/SSL_KEY,
e.g. compute protocol = useHttps ? 'https' : 'http' and use that in the
c.bright(...) output so the log reflects the real server mode (refer to the
`useHttps` variable and the existing console.log line).
- Around line 193-207: Wrap the SSL certificate reading and HTTPS server
creation in a try/catch to handle read permissions, invalid/corrupt certs, or
createServer errors: when SSL_CERT/SSL_KEY are present and files exist, attempt
to fs.readFileSync both files and call https.createServer inside a try block,
set a boolean flag useHttps = true on success and fall back to http.createServer
with useHttps = false on any thrown error; ensure processLogger/console.error
logs include the caught error and a clear message; finally, update the
startup/protocol log to reference the useHttps flag (not just presence of
SSL_CERT/SSL_KEY) so it accurately reflects whether the HTTPS server was
actually created.
- Wrap SSL certificate reading and HTTPS server creation in try/catch - Add useHttps flag to track actual server state - Update protocol log to use useHttps flag instead of env vars - Gracefully fallback to HTTP if certificate loading fails Addresses code review feedback from CodeRabbit. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Allow configuring a separate port for HTTPS via SSL_PORT environment variable. When SSL is enabled and SSL_PORT is set, the server listens on that port. Otherwise, it falls back to PORT. This enables common setups where HTTP runs on port 3001 and HTTPS runs on port 443. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Summary
SSL_CERTandSSL_KEYenvironment variablesFixes #361
Changes
server/index.js: Importhttpsmodule, conditionally create HTTPS server when SSL configured.env.example: Added SSL/TLS configuration section with documentationExample Usage
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.