Skip to content
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

Streaming throws on 301 response from an instance #2183

Open
not7cd opened this issue Jun 14, 2024 · 3 comments
Open

Streaming throws on 301 response from an instance #2183

not7cd opened this issue Jun 14, 2024 · 3 comments

Comments

@not7cd
Copy link

not7cd commented Jun 14, 2024

As I'm trying to connect to my instance with client.publicStreaming(), I'm getting this exception

Error: Unexpected server response: 301
    at ClientRequest.<anonymous> (/data/node_modules/node-red-contrib-megalodon/node_modules/ws/lib/websocket.js:912:7)
    at ClientRequest.emit (node:events:513:28)
    at HTTPParser.parserOnIncomingClient (node:_http_client:693:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
    at TLSSocket.socketOnData (node:_http_client:534:22)
    at TLSSocket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)

It may be connected to a default nginx config that forces TLS?
I'm not sure how to debug this. I'm using a slightly modified streaming example from readme.
https://github.com/not7cd/node-red-contrib-megalodon/blob/fa9c3b49f51208cffb59d793108b79ab563de272/src/streaming.js

@not7cd
Copy link
Author

not7cd commented Jun 14, 2024

Quick search suggests changing the url from ws:// to wss://.

@not7cd
Copy link
Author

not7cd commented Jun 14, 2024

I was able to hack a solution in transpiled JS.
Two fixes were needed in my case.
Append / to /api/v1/streaming. This solved 301 redirect to /api/v1/streaming/. Not sure where this came from.

I also had to add .trim() in Streaming, as for some reason, space %20 was being added here. It may be a bug coming from my implementation in Node-RED. But it may be worth to add sanitization in the lib.

parameter.push("access_token=".concat(accessToken.trim()));

@h3poteto
Copy link
Owner

Which server did you use?
Please provide a sample code to reproduce this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants