Skip to content

Instantly share code, notes, and snippets.

@PavelDemyanenko
Last active August 29, 2015 14:13
Show Gist options
  • Save PavelDemyanenko/6ec3a5d280cea2b9299e to your computer and use it in GitHub Desktop.
Save PavelDemyanenko/6ec3a5d280cea2b9299e to your computer and use it in GitHub Desktop.
Simple web-server with url parsing.
var http = require("http");
var url = require("url");
function example(route, routes) {
function onRequest(req, res) {
var pathname = url.parse(req.url).pathname;
console.log("Request for " + pathname + " recieved.");
route(pathname, routes, res);
}
http.createServer(onRequest).listen(1337);
console.log("Server running at http://127.0.0.1:1337/");
}
exports.example = example;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment