Skip to content

Conversation

@iceljc
Copy link
Collaborator

@iceljc iceljc commented Jul 17, 2025

PR Type

Bug fix


Description

  • Fix WebSocket URL construction by adding missing slashes

Diagram Walkthrough

flowchart LR
  A["PUBLIC_SERVICE_URL"] --> B["Split by ://"]
  B --> C["Check protocol"]
  C --> D["Add missing slashes"]
  D --> E["Valid WebSocket URL"]
Loading

File Walkthrough

Relevant files
Bug fix
realtime-chat-service.js
Fix WebSocket URL protocol formatting                                       

src/lib/services/realtime-chat-service.js

  • Add missing forward slashes in WebSocket URL construction
  • Fix wss: to wss:// and ws: to ws://
  • Remove unnecessary empty line
+2/-3     

@iceljc iceljc merged commit 3c073de into SciSharp:main Jul 17, 2025
1 of 2 checks passed
@qodo-merge-pro
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Edge Case

The function returns an empty string when PUBLIC_SERVICE_URL doesn't start with 'https' or 'http', which could cause issues if the URL has a different format or is malformed.

function buildWebsocketUrl() {
    let url = '';
    const host = PUBLIC_SERVICE_URL.split('://');

    if (PUBLIC_SERVICE_URL.startsWith('https')) {
        url = `wss://${host[1]}`;
    } else if (PUBLIC_SERVICE_URL.startsWith('http')) {
        url = `ws://${host[1]}`;
    }
    return url;
}

@qodo-merge-pro
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Add fallback for unsupported protocols

Add a fallback case to handle URLs that don't start with 'http' or 'https'.
Currently, if PUBLIC_SERVICE_URL has an unexpected protocol, the function
returns an empty string which could cause WebSocket connection failures.

src/lib/services/realtime-chat-service.js [134-138]

 if (PUBLIC_SERVICE_URL.startsWith('https')) {
     url = `wss://${host[1]}`;
 } else if (PUBLIC_SERVICE_URL.startsWith('http')) {
     url = `ws://${host[1]}`;
+} else {
+    throw new Error(`Unsupported protocol in PUBLIC_SERVICE_URL: ${PUBLIC_SERVICE_URL}`);
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out that an unsupported protocol in PUBLIC_SERVICE_URL would lead to a silent failure, and proposing to throw an error improves robustness and debuggability.

Medium
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant