I am Trying to add socket.io-client in angular 2.
I already installed the modules and all and probably more than I need of the typings:
npm install @types/socket.io --save-dev
npm install @types/socket.io-client --save-dev
typings install dt~socket.io-client --save --global
typings install dt~socket.io --save --global
And I tried importing it in my component attempting two different ways:
import * as io from "socket.io-client";
//declare var io:any;
Yet, im still getting this error in my browser:
http://localhost:4200/socket.io/?EIO=3&transport=polling&t=LeKQjxc 404 (Not Found)
same problem for me, I currently trying to connect to a test socket from wss://echo.websocket.org but automatically /socket.io/ is added which leads to a 404-response
Any updates? I'm getting the same thing trying to integrate socket.io into our app. Using Angular CLI, installed the types, and included them in the tsconfig.app.json
, but I'm still getting the same 404 error. Seems like it works for everybody else, but not for us!
Could you please provide the configuration for the server?
@darrachequesne Hi! Yup it worked after I checked the server configuration the next day. It was a really silly oversight on my part... Sorry for bumping the issue! Not sure about the others above though. Thanks again!
@crebuh you won't be able to connect to wss://echo.websocket.org
, as socket.io is not a Websocket implementation (it uses Websocket as a possible transport).
@AhadCove Could you please provide the configuration for the server?
@darrachequesne our problem was the nginx configuration we had to add this location
location ~/(socket\.io).*$ {
proxy_pass http://127.0.0.1:6005;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
then it worked :)
@crebuh great! I think we can close this issue now, please reopen if needed.
Most helpful comment
@darrachequesne our problem was the nginx configuration we had to add this location
location ~/(socket\.io).*$ { proxy_pass http://127.0.0.1:6005; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; }
then it worked :)