I created my React app using Create React App in version 3.1.2 (19 Sept 2019). I was trying to configure proxy for Web Socket requests, but it seems that when I am using the proxy, the connection is not established. I have used THIS example to set up my things. The server is Asp.Net Core as in example and it works as long as it has the address wired into the initalization. This snippet works:
const hubConnection = new HubConnectionBuilder()
.withUrl("https://localhost:44392/chatHub")
.build();
And this doesn't:
const hubConnection = new HubConnectionBuilder()
.withUrl("chatHub")
.build();
With this:
{
"proxy": "https://localhost:44392/",
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@microsoft/signalr": "^3.0.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-scripts": "3.1.2"
},
(...)
I saw a suggestion HERE that I might use an object in proxy setup, but when I tried I got an error that proxy address has to be a single string, not an object:
proxy: {
'^/api': {
target: '<url>',
ws: true,
changeOrigin: true
},
'^/foo': {
target: '<other_url>'
}
.withUrl("/chatHub")