Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load resource #20

Open
josefrm opened this issue Jan 4, 2016 · 2 comments
Open

Failed to load resource #20

josefrm opened this issue Jan 4, 2016 · 2 comments

Comments

@josefrm
Copy link

josefrm commented Jan 4, 2016

Hello there I'm working with:

Ubutu 14.04
Express 4.10.2
Socket.io 1.3.7

Vagrant
Port fowarding :8001 to Box :80
Port fowarding :8002 to Box :3000

This is my App.js

var express = require('express');
var app = express();
var server = app.listen(3000);

var io = require('socket.io').listen(server);
var http = require('http');

io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});

and this is my index.html

<!doctype html>

<title>Socket.IO chat</title> <style> \* { margin: 0; padding: 0; box-sizing: border-box; } body { font: 13px Helvetica, Arial; } form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } #messages { list-style-type: none; margin: 0; padding: 0; } #messages li { padding: 5px 10px; } #messages li:nth-child(odd) { background: #eee; } </style>
    Send <script src="https://cdn.socket.io/socket.io-1.3.7.js"></script> <script src="http://code.jquery.com/jquery-1.11.1.js"></script> <script> var socket = io.connect(); </script>

    then when I open in the browser the index page I get:

    Failed to load resource: the server responded with a status of 404 (Not Found)
    http://127.0.0.1:8001/socket.io/?EIO=3&transport=polling&t=1451934295598-10

    any idea how to solve it?

    @anubhav7495
    Copy link

    var express = require('express');
    var app = express();
    var http = require('http').Server(app);
    var io = require('socket.io')(http);
    
    app.get('/', function(req,res) {
      res.sendFile(__dirname + '/index.html');
    });
    
    io.on('connection', function(socket) {
      console.log('a user connected')
      socket.on('disconnect', function() {
        console.log('a user disconnected');
      });
    });
    
    http.listen(3000, function() {
      console.log('Listening on port 3000');
    });
    

    Try this! Works for me.

    @Seliniux777
    Copy link

    var app = require('express')();
    var http = require('http').Server(app);

    app.get('/', function(req, res){
    res.sendfile('index.html');
    });

    http.listen(3000, function(){
    console.log('listening on *:3000');
    });
    We'll need an index.html file to serve, create a new file called index.html and enter the following in it:

    <title>Hello world</title> Hello world To test if this works, go to your terminal and run this app using

    nodemon app.js

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants