pubsub-example icon indicating copy to clipboard operation
pubsub-example copied to clipboard

Make functional from clone

Open diegovillafuerte1 opened this issue 4 years ago • 2 comments

include instructions on installing dependencies, and hosting static files in the readme e.g. npm init npm install uNetworking/uWebSockets.js#v18.10.0 python -m http.server

diegovillafuerte1 avatar Nov 20 '20 17:11 diegovillafuerte1

yes its a bit confusing trying to figure out how to get the app running, with socket.io or uWebsockets...

typically u'd want the server to point to the client.html with express, so I'm wondering how you even serve the client file locally

fractalfantasy avatar May 04 '21 17:05 fractalfantasy

I can't figure out how to get the app running locally, a typical socket.io app would look like this >> pointing to an index.html file

var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var fs = require('fs');

app.listen(80);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

io.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

fractalfantasy avatar May 04 '21 17:05 fractalfantasy