Skip to content

Instantly share code, notes, and snippets.

@geoffrasb
Created March 1, 2012 18:19
Show Gist options
  • Save geoffrasb/1951882 to your computer and use it in GitHub Desktop.
Save geoffrasb/1951882 to your computer and use it in GitHub Desktop.
simple route
//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