Permalink
Browse files

Added vhost example. Closes #144

  • Loading branch information...
1 parent cf40e85 commit c5c883dd28e852b855159aebb8e32186521ad1bd @tj tj committed Aug 17, 2011
Showing with 12 additions and 15 deletions.
  1. +1 −0 examples/pids.js
  2. +11 −15 examples/vhost.js
View
@@ -14,6 +14,7 @@ var server = http.createServer(function(req, res){
});
cluster(server)
+ .use(cluster.debug())
.use(cluster.pidfiles())
.use(cluster.logger())
.listen(3000);
View
@@ -4,34 +4,30 @@
*/
var cluster = require('../')
- , http = require('http')
, connect = require('connect');
-// edit /etc/hosts
-// 127.0.0.1 foo.com
-// 127.0.0.1 bar.com
+// setup:
+// $ npm install connect
+// $ edit /etc/hosts
-var app = http.createServer(function(req, res){
+var server = connect();
+
+var foo = connect().use(function(req, res){
var body = 'Hello from foo.com';
res.writeHead(200, { 'Content-Length': body.length });
res.end(body);
});
-var app2 = http.createServer(function(req, res){
+var bar = connect().use(function(req, res){
var body = 'Hello from bar.com';
res.writeHead(200, { 'Content-Length': body.length });
res.end(body);
});
-var server = connect.createServer();
-
-server.use(connect.vhost('foo.com', app));
-server.use(connect.vhost('bar.com', app2));
-server.use(function(req, res){
- res.writeHead(200);
- res.end('Visit foo.com or bar.com');
-});
+server.use(connect.vhost('foo.com', foo));
+server.use(connect.vhost('bar.com', bar));
cluster(server)
+ .set('workers', 4)
.use(cluster.debug())
- .listen(80);
+ .listen(3000);

0 comments on commit c5c883d

Please sign in to comment.