Skip to content

Instantly share code, notes, and snippets.

@linus
Created October 14, 2011 10:16
Show Gist options
  • Save linus/1286740 to your computer and use it in GitHub Desktop.
Save linus/1286740 to your computer and use it in GitHub Desktop.
Matching POSTed data for artemma
var http = require("http");
// Responses for various urls
var responses = {
"/createUser": "foo",
"/deleteUser": "bar"
};
var server = http.createServer(function(req, res) {
// Listen for data on request
var body = "";
req.on("data", function(chunk) {
body += chunk;
});
req.on("end", function() {
res.writeHead(200, { "content-type": "text/plain" });
if(body.match(/somethingcool/)) {
res.end(responses[req.url]);
} else {
res.end("err");
}
});
});
server.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment