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

Not supporting with Express 3.0 #843

Closed
scarvell opened this Issue Apr 20, 2012 · 9 comments

Comments

Projects
None yet
8 participants
@scarvell

scarvell commented Apr 20, 2012

socket.io keeps throwing 404 errors only when running on express version 3 (server is fine, its just the route on the client)

For anyone else having this issue, this hack can be applied to get around it:

var fs = require('fs');
app.get('/socket.io/socket.io.js', function(req, res) {
    fs.readFile('/PROJECT_HOME/node_modules/socket.io/lib/socket.io.js', function(error, content) {
        if (error) {
            res.writeHead(500);
            res.end();
        }
        else {
            res.writeHead(200, { 'Content-Type': 'text/javascript' });
            res.end(content, 'utf-8');
        }
   });
});

Thanks @deltanovember

@defunctzombie

This comment has been minimized.

Show comment
Hide comment
@defunctzombie

defunctzombie Apr 20, 2012

Contributor

instead of hard coding the path I think you should do:

path.join(require('socket.io-client').dist, 'socket.io.min.js');

Or something to that effect.

Contributor

defunctzombie commented Apr 20, 2012

instead of hard coding the path I think you should do:

path.join(require('socket.io-client').dist, 'socket.io.min.js');

Or something to that effect.

@pyrotechnick

This comment has been minimized.

Show comment
Hide comment
@pyrotechnick

pyrotechnick Apr 21, 2012

The issue is that as of express@3, express.createServer (now aliased as simply express) now returns an express.application rather than an http.Server.

Fortunately you can still get at the server. Have socket.io listen on the return value of listen rather than the return value of express / express.createServer...

express = require 'express'

app = express()
server = app.listen 3000
io = require('socket.io').listen server

This goes for anything else utilising connect@2 since it's within connect where the changes were made...

https://github.com/senchalabs/connect/blob/1.x/lib/connect.js#L65

function createServer() {
  if ('object' == typeof arguments[0]) {
    return new HTTPSServer(arguments[0], Array.prototype.slice.call(arguments, 1));
  } else {
    return new HTTPServer(Array.prototype.slice.call(arguments));
  }
};

https://github.com/senchalabs/connect/blob/master/lib/connect.js#L59

function createServer() {
  function app(req, res){ app.handle(req, res); }
  utils.merge(app, proto);
  utils.merge(app, EventEmitter.prototype);
  app.route = '/';
  app.stack = [].slice.apply(arguments);
  return app;
};

From senchalabs/connect#520 ...

@visionmedia (senchalabs/connect#520 (comment))
In 2.x we can break a few little things like this, it was a bad idea from the beginning, you can't manipulate it progressively and you have no access to mounting so it's inevitable that you'll have to break it out into .use() calls at some point

pyrotechnick commented Apr 21, 2012

The issue is that as of express@3, express.createServer (now aliased as simply express) now returns an express.application rather than an http.Server.

Fortunately you can still get at the server. Have socket.io listen on the return value of listen rather than the return value of express / express.createServer...

express = require 'express'

app = express()
server = app.listen 3000
io = require('socket.io').listen server

This goes for anything else utilising connect@2 since it's within connect where the changes were made...

https://github.com/senchalabs/connect/blob/1.x/lib/connect.js#L65

function createServer() {
  if ('object' == typeof arguments[0]) {
    return new HTTPSServer(arguments[0], Array.prototype.slice.call(arguments, 1));
  } else {
    return new HTTPServer(Array.prototype.slice.call(arguments));
  }
};

https://github.com/senchalabs/connect/blob/master/lib/connect.js#L59

function createServer() {
  function app(req, res){ app.handle(req, res); }
  utils.merge(app, proto);
  utils.merge(app, EventEmitter.prototype);
  app.route = '/';
  app.stack = [].slice.apply(arguments);
  return app;
};

From senchalabs/connect#520 ...

@visionmedia (senchalabs/connect#520 (comment))
In 2.x we can break a few little things like this, it was a bad idea from the beginning, you can't manipulate it progressively and you have no access to mounting so it's inevitable that you'll have to break it out into .use() calls at some point

@Ry7n

This comment has been minimized.

Show comment
Hide comment
@Ry7n

Ry7n Jun 26, 2012

It took a surprising amount of searching to find this workaround. Perhaps the socket.io web site should be updated with a new code example?

Ry7n commented Jun 26, 2012

It took a surprising amount of searching to find this workaround. Perhaps the socket.io web site should be updated with a new code example?

@sreekumar-kr

This comment has been minimized.

Show comment
Hide comment
@nategood

This comment has been minimized.

Show comment
Hide comment
@nategood

nategood Aug 29, 2012

@RCanine agreed. It seems like documentation for both express 3.0 and socket.io is very lacking as of late. I've found myself sifting through github code far more than I ever recalled doing in the past.

nategood commented Aug 29, 2012

@RCanine agreed. It seems like documentation for both express 3.0 and socket.io is very lacking as of late. I've found myself sifting through github code far more than I ever recalled doing in the past.

@rauchg

This comment has been minimized.

Show comment
Hide comment
@rauchg

rauchg Aug 29, 2012

Contributor

Express 3 is a RC last time I checked?

Contributor

rauchg commented Aug 29, 2012

Express 3 is a RC last time I checked?

@tj

This comment has been minimized.

Show comment
Hide comment
@tj

tj Aug 29, 2012

Contributor

when you upgrade to a new major release of a library read the changelog / migration guides please, things have obviously changed

Contributor

tj commented Aug 29, 2012

when you upgrade to a new major release of a library read the changelog / migration guides please, things have obviously changed

@rauchg

This comment has been minimized.

Show comment
Hide comment
@rauchg

rauchg Aug 29, 2012

Contributor

We have an example for Express3 in the README, and I've just updated socket.io with an example as well.

Contributor

rauchg commented Aug 29, 2012

We have an example for Express3 in the README, and I've just updated socket.io with an example as well.

@rauchg rauchg closed this Aug 29, 2012

@tj

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment