Skip to content

Instantly share code, notes, and snippets.

@codedot
Created May 1, 2012 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codedot/2570196 to your computer and use it in GitHub Desktop.
Save codedot/2570196 to your computer and use it in GitHub Desktop.
Uniweb Server Helper
var start = require("uniwebjs");
//var read = require("fs").readFileSync;
function hello(socket, data) {
if (data) {
socket.run(function(data) {
window.alert(data);
}, data);
} else {
socket.run(function() {
socket.say("Hello World!");
});
}
}
start(hello, {
// domain: "example.com",
// key: read("key.pem"),
// cert: read("cert.pem"),
port: 8080,
portssl: null
});
{
"author": "Anton Salikhmetov",
"description": "JSON Helper for Uniweb",
"name": "uniwebjs",
"version": "0.0.0",
"scripts": {
"test": "node hello.js"
},
"dependencies": {
"uniweb": "*"
},
"engines": {
"node": "*"
},
"main": "uniwebjs"
}
module.exports = function(server, options) {
var start = require("uniweb");
options.handler = function(socket) {
socket.on("message", function(data) {
server(socket, JSON.parse(data));
});
socket.run = function(f, x) {
f = f.toString();
x = JSON.stringify(x);
this.send("(" + f + ")(" + x + ")");
};
socket.run(function() {
socket.say = function(data) {
data = JSON.stringify(data);
this.send(data);
};
});
server(socket);
};
start(options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment