Skip to content

Instantly share code, notes, and snippets.

@DTrejo
Created December 5, 2010 06:57
Show Gist options
  • Save DTrejo/728894 to your computer and use it in GitHub Desktop.
Save DTrejo/728894 to your computer and use it in GitHub Desktop.
dtrejo.com w/ proxying to compare
var util = require('sys') // update this at some point
, ns = require('node-static')
, http = require('http')
, fileServer = new ns.Server('./public');
http.createServer(function (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response, function (err, result) {
if (err) { // An error as occurred
util.error("> Error serving " + request.url + " - " + err.message + ' - '+ err.status);
// if you put 404 as the status, it won't get to the client
fileServer.serveFile('404.html', 200, err.headers, request, response);
} else { // The file was served successfully
// console.log('> ' + request.url + ' - ' + res.message);
// console.log('hit static');
}
});
});
}).listen(8080);
console.log("\nListening on http://localhost:" + 8080 + "/ with node-static@"+ns.version+" and node@"+process.version+"\n");
//
// Proxy shit to my other apps! awww yeah!
//
var httpProxy = require('http-proxy');
var options = {
router: { 'dtrejo.com': '127.0.0.1:8080'
, 'www.dtrejo.com': '127.0.0.1:8080'
, 'compresscompare.dtrejo.com': '127.0.0.1:8081'
, '^((?:[a-z][a-z0-9_]*)).dtrejo.com': '127.0.0.1:8080'
, 'localhost': '127.0.0.1:8080'
}
};
var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment