-
-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[help wanted] Manually proxy settings to open connection with websocket.org #2260
Comments
@jamesblight Mind looking at this? |
As I found out when I'm using web sockets, it is not necessary to turn on the proxy, because requests are going not through http/https, but through ws/wss (example: But I'm still confused about: why after setting proxy to use sockets like: "target": "link",
"ws": true url for request generates like: sockets.io-client propose to fix this issue, with next server and client configuration: Looks like that is not an issue of create-react-app, so will open the question at StackOverflow. P.S: will keep that issue up to date after closing. |
Thanks. If you find an answer please don’t hesitate to send a PR to our docs 😉 |
@yuzhva @gaearon I spent a bit of time investigating this issue. The proxy is working, but ws://echo.websocket.org is not running a socket.io server. This is why you're seeing a 404 response. If you use socket.io, you need to use a socket.io server. If you look at the network requests with and without the proxy defined in
TLDR; socket.io client will only work with a socket.io server, and websocket.org doesn't support this. If you want to proxy a websocket connection, you can use plain Websockets (without socket.io) If you want to use socket.io, you can run your own local socket.io server to connect to:
Then, setup your proxy:
|
@jamesblight Anything we could add to the docs? |
@gaearon Not sure if you need to add this to Is note like would be helpful?
|
@jamesblight I added an extra note to your fork. |
UPDATE: Final words. If you would like to connect WebSocket server that already hosted at Also, you don't need to configure a proxy for that purpose. The solution will be: After creating app like class App extends Component {
constructor(props) {
super(props);
this.socket = new WebSocket('ws://echo.websocket.org');
}
componentDidMount() {
this.socket.onmessage = (message) => {
const messageData = JSON.stringify(message);
console.log(messageData);
}
// Give some time for socket to establish connection
setTimeout(() => {
this.socket.send('create-react-app');
}, 3000);
} |
Hey hi.
Since
react-scripts@1.0.0
and higher create-react-app support manual proxy settings.After creating app like
I installed socket
yarn add socket.io-client
, added proxy settings to thepackage.json
like:changed
src/App.js
:But when I'm opening the console, I can see that request actually goes through HTTP and I'm getting 404 response, because there is no that page (this page exists only for web socket request)
Expected behavior:
When I'll resolve that, will open PR with an example in improved documentation.
The text was updated successfully, but these errors were encountered: