Created
January 15, 2013 19:00
-
-
Save soheilhy/4541040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var hello = function(req, res) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.write('Hello! <br />'); | |
res.write('<br />' + | |
'URL:' + req.url + '<br />' + | |
'Method:' + req.method + '<br />'); | |
}; | |
var send404 = function(req, res) { | |
res.writeHead(404, {'Content-Type': 'text/html'}); | |
res.write('Ooops! No resource found at this URL!'); | |
}; | |
http.createServer(function(req, res) { | |
if (req.url.indexOf('/hello') != -1) { | |
hello(req, res); | |
} else { | |
send404(req, res); | |
} | |
res.end(); | |
}).listen(4321, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:4321/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment