Skip to content

CRA server disconnects my websocket connection #12380

@Valter4o

Description

@Valter4o

I am using http-proxy-middleware to intercept my websocket request from the app, because I need to send cookies to BE, and Chrome doesn't attach cookies to external domains, so my only solution is to proxy the request and make the wesocket connection via the CRA server.

This is my config in the setupProxy.js

code4e

I am running a demo nodejs server on port 8080 and /testws is the endpoint to connect the websocket to. This is how I try to connect to the websocket, I am using the standart JS websocket

image

Note: I use wss because the project is served in https, and in ws it fails to connect to the proxy.

Below is the output in the terminal when I connect to the proxy.

image

The server just disconnects, doesn't throw error, onError callback in the proxy config doesn't log, it just disconnects immediatelly, it doesn't even connect to the server, I log a msg on every connection on the nodejs server and it doesn't log at all.

I can connect to the server if I don't use the proxy like this
image
but then again Chrome doesn't attach cookies to the request and I need them to authenticate with our real BE

I would be grateful for all kinds of suggestions. Also it is not an option for the BE to change, so please constrain from suggesting changes related to the BE. I just need to make the CRA app to make the connection. If it isn't possible, which I doubt, then we will consider changing the BE as well

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions