Created
December 1, 2012 11:10
-
-
Save buschtoens/4181547 to your computer and use it in GitHub Desktop.
Node.js domain distribution
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
var http = require("http") | |
, net = require("net") | |
, fs = require("fs"); | |
try { fs.mkdirSync("/tmp/http", 0777); } catch(e) {} | |
fs.chmodSync("/tmp/http", 0777); | |
http.createServer(function(req, res) { | |
var options = { | |
method: req.method | |
, path: req.url | |
, headers: req.headers | |
, socketPath: "/tmp/http/" + req.headers.host | |
}; | |
var proxy_req = http.request(options, function(proxy_res) { | |
res.writeHead(proxy_res.statusCode, proxy_res.headers); | |
proxy_res.pipe(res); | |
}); | |
proxy_req.on("error", function(error) { | |
res.write("Something went wrong :(\n\n"); | |
res.write("Domain: " + req.headers.host + "\n\n"); | |
res.end(); | |
}); | |
req.pipe(proxy_req); | |
}).listen(80); |
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
var http = require("http"); | |
http.createServer(function(req, res) { | |
res.end("Hey, my name is test.com"); | |
}).listen("/tmp/http/test.com"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment