Example #1
0
var nspDesktop = io.of('/desktop');


nspDesktop.on('connection', function(socket) {
    socket.on('end', function (data) {
        nspMobile.emit('end');
    })
});

nspMobile.on('connection', function(socket) {
    socket.on('movement', function (data) {
        nspDesktop.emit('movement', data);
    })
});

dispatcher.setStatic("static");
dispatcher.setStaticDirname('.');

function serveIndex(req, res) {
    var parsed = uaparse(req.headers['user-agent']);
    if(parsed.os.name === 'iOS' || parsed.os.name === 'Android') {
        req.url = '/static/index_mobile.html';
        fs.readFile('static/index_mobile.html', function (err, data) {
            if (err) {
                res.response.writeHead(500);
                res.end();
                return;
            }
            res.end(data.toString().replace('localhost:8081', req.headers.host.replace('8080', '8081')));
        })
    }
Example #2
0
        dispatcher.dispatch(request, response);
    } catch(err) {
        console.log(err);
    }
}


//Create a server
var server = http.createServer(handleRequest);

//Lets start our server
server.listen(PORT, function(){
    //Callback triggered when server is successfully listening. Hurray!
    console.log("Server listening on: http://localhost:%s", PORT);
});


//For all your static (js/css/images/etc.) set the directory name (relative path).
dispatcher.setStatic('resources');

//A sample GET request    
dispatcher.onGet("/page1", function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Page One');
});    

//A sample POST request
dispatcher.onPost("/post1", function(req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Got Post Data');
});
function handleRequest(e,t){try{console.log(e.url),dispatcher.dispatch(e,t)}catch(n){console.log(n)}}var http=require("http"),dispatcher=require("httpdispatcher");const PORT=8080;var server=http.createServer(handleRequest);dispatcher.setStatic("/images/"),dispatcher.onGet("/page1",function(e,t){t.writeHead(200,{"Content-Type":"text/plain"}),t.end("Page One")}),dispatcher.onPost("/post1",function(e,t){t.writeHead(200,{"Content-Type":"text/plain"}),t.end("Got Post Data")}),server.listen(PORT,function(){console.log("Server Listening on: http://localhost:%s",PORT)});
var dispatcher  =   require("httpdispatcher");

const PORT=8080

function handleRequest(request, response) {
  try {
    console.log(request.url);
    dispatcher.dispatch(request, response);
  } catch(err) {
    console.log(err)
  };
};

var server = http.createServer(handleRequest);

dispatcher.setStatic("/images/")

dispatcher.onGet("/page1", function(req, res) {
  res.writeHead(200, {"Content-Type" : "text/plain"});
  res.end("Page One");
});

dispatcher.onPost("/post1", function(req, res) {
  res.writeHead(200, {"Content-Type": "text/plain"});
  res.end("Got Post Data");
});



server.listen(PORT, function() {
  console.log("Server Listening on: http://localhost:%s", PORT)
Example #5
0
var http        = require('http'),
    dispatcher  = require('httpdispatcher'),
    fs          = require('fs');

var PORT    = 1234,
    server  = http.createServer();

server.on('request', function (request, response) {
        dispatcher.dispatch(request, response);
    })
    .listen(PORT, function () {
        console.log('Server listening on: http://localhost:%s', PORT);
    });

dispatcher.setStaticDirname(__dirname);
dispatcher.setStatic('public');

dispatcher.onGet('/', function (request, response) {
    var file_path = 'index.html';

    fs.exists(file_path, function (exists) {
        if (exists) {
            fs.readFile(file_path, function (err, file) {
                response.writeHead(200, { 'Content-Type': 'text/html' });
                response.end(file);
            });
        } else {
            response.writeHead(500, { 'Content-Type': 'text/plain' });
            response.end('500 Interval error');
        }
    });