79580578

Date: 2025-04-18 07:11:48
Score: 1
Natty:
Report link

The issue is likely in how you're establishing the WebSocket connection to the Rust backend. When using ws in Node.js environment (your Next.js API route), the headers need to be passed differently than what you have in your code.

  1. In your Next.js handler, you're creating a WebSocket connection like this:

const socketRust = new WebSocket(wsUrl, { headers: { api_key: token, }, });

But the ws package in Node.js expects headers to be passed differently when used on the server side.

Try modifying your code like this:

const socketRust = new WebSocket(wsUrl, { headers: { 'API-Key': token, // Make sure case matches what your Rust server expects } });

If that doesn't work, another approach is to use the request option:

const socketRust = new WebSocket(wsUrl, { rejectUnauthorized: false, // Only for development! headers: { 'API-Key': token, } });

Also, check if your Rust backend expects the header to be "api_key" or "API-Key"

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Sankalp Kamble