Skip to content

Use a single http server #3

Description

@kmturley

In your documentation you explain running
node ./server.js

Then running:
python -m SimpleHTTPServer

or
http-server

In fact you are already have a node http server running you can use to server the files. Simple change server.js to server static files via the handler:

function handler (req, res) {
  if (req.url === '/') {
    req.url = '/index.html';
  }
  console.log('handler', req.url);
  fs.readFile(__dirname + '/src' +  req.url, function (err,data) {
    if (err) {
      res.writeHead(404);
      res.end(JSON.stringify(err));
      return;
    }
    res.writeHead(200);
    res.end(data);
  });
}

Now both Socket.io and the http server will be running on the same address and port

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions