Created
March 1, 2012 18:19
-
-
Save geoffrasb/1951882 to your computer and use it in GitHub Desktop.
simple route
This file contains hidden or 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
//114.34.230.1 | |
//192.168.1.100 | |
var http = require('http'); | |
var fs = require('fs'); | |
var url = require('url'); | |
http.createServer(function (req, res) { | |
var pathname = url.parse(req.url).pathname; | |
console.log(pathname); | |
if(pathname=='/') | |
pathname='/index.html'; | |
fs.readFile('.'+pathname,function(error,content){ | |
if(error){ | |
res.writeHead(500); | |
res.end(); | |
}else{ | |
var contentType; | |
if(pathname.match(/.*\.html+/)) | |
contentType="text/html"; | |
else if(pathname.match(/.*\.css$/)) | |
contentType="text/css"; | |
res.writeHead(200,{'Content-Type': contentType}); | |
res.end(content,'utf-8'); | |
} | |
}); | |
}).listen(1337, "192.168.1.100"); | |
console.log('Server running '); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment