Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created July 19, 2011 17:41
Show Gist options
  • Save eminetto/1093224 to your computer and use it in GitHub Desktop.
Save eminetto/1093224 to your computer and use it in GitHub Desktop.
server.js
//http://net.tutsplus.com/tutorials/javascript-ajax/learning-serverside-javascript-with-node-js/
//http://www.toxiccoma.com/random/nodejs-0195-http-post-handling-of-form-data
var sys = require("sys"),
http = require("http"),
querystring = require('querystring');
//cria o servidor
http.createServer(function(request, response) {
post_handler(request, function(request_data)
{
//publica o evento
var pubsub = require('pubsub.io').connect().publish({name: 'events', title: request_data.title, detail: request_data.detail, user: request_data.user});
response.end();
});
}).listen(8888);
function post_handler(request, callback)
{
var _REQUEST = { };
var _CONTENT = '';
if (request.method == 'POST')
{
request.addListener('data', function(chunk)
{
_CONTENT+= chunk;
});
request.addListener('end', function()
{
_REQUEST = querystring.parse(_CONTENT);
callback(_REQUEST);
});
};
};
sys.puts("Server running at http://localhost:8080/");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment