node.js - Failed to load resource: the server responded with a status of 404 (Not Found) socket.io/?EIO=3&transport=polling&t=1503062449710-0 -


i able deploy app azure, error socket.io

 /socket.io/?eio=3&transport=polling&t=1503062449710-0 failed load resource: server responded status of 404 (not found)  

even though worked on localhost.

server side:

var app = require('express')(); var server = require('http').server(app); var io = require('socket.io')(server);  server.listen(80);  app.get('/', function (req, res) {   res.sendfile(__dirname + '/index.html'); });  io.on('connection', function (socket) {   socket.emit('news', { hello: 'world' });   socket.on('my other event', function (data) {     console.log(data);   }); }); 

client side (index.html):

<html>  <head>     <script src="/socket.io/socket.io.js"></script>     <script>         var socket = io.connect('http://chattranslatortwo.azurewebsites.net/');         socket.on('news', function(data) {             console.log(data);             socket.emit('my other event', {                 my: 'data'             });         });     </script> </head> <body> </body> </html> 

now i've done many things attempt fix this.

1) since many posts saying change socket.io socket.io-client, or "https://cdn.socket.io/socket.io-1.3.7.js" didn't change me, same result.

2) tried reinstalling node.js , socket.io, wasn't sure if changed either.

3) enabled azure web sockets in application settings

4) made sure connection correct site.

i come same error message calling out socket.io:

/socket.io/?eio=3&transport=polling&t=1503062449710-0 failed load resource: server responded status of 404 (not found) 

either i'm missing or seems sockets work different on webservices localhost.

i've been working on problem quite time now.

on azure app service, you'd need change following line

server.listen(80);  

to

server.listen(process.env.port); 

also, should create web.config in root of node.js application if not exists. reference, below default web.config application uses app.js entry point.

<?xml version="1.0" encoding="utf-8"?> <!--        configuration file required if iisnode used run node processes behind        iis or iis express.  more information, visit:         https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config   --> <configuration>   <system.webserver>     <!-- visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx more information on websocket support -->     <websocket enabled="false" />     <handlers>       <!-- indicates server.js file node.js web app handled iisnode module -->       <add name="iisnode" path="app.js" verb="*" modules="iisnode" />     </handlers>     <rewrite>       <rules>         <!-- not interfere requests node-inspector debugging -->         <rule name="nodeinspector" patternsyntax="ecmascript" stopprocessing="true">           <match url="^app.js\/debug[\/]?" />         </rule>         <!-- first consider whether incoming url matches physical file in /public folder -->         <rule name="staticcontent">           <action type="rewrite" url="public{request_uri}" />         </rule>         <!-- other urls mapped node.js web app entry point -->         <rule name="dynamiccontent">           <conditions>             <add input="{request_filename}" matchtype="isfile" negate="true" />           </conditions>           <action type="rewrite" url="app.js" />         </rule>       </rules>     </rewrite>     <!--         can control how node hosted within iis using following options:           * watchedfiles: semi-colon separated list of files watched changes restart server           * node_env: propagated node node_env environment variable           * debuggingenabled - controls whether built-in debugger enabled          see https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config full list of options       -->     <!--<iisnode watchedfiles="web.config;*.js"/>-->   </system.webserver> </configuration> 

for more information, please refer create node.js chat application socket.io in azure app service.


Comments