Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added vhost example

  • Loading branch information...
commit 7ede5b13a9b829ff25557ec0d6f483f6bd45ada8 1 parent 0a4944d
@tj tj authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 examples/vhost.js
View
37 examples/vhost.js
@@ -0,0 +1,37 @@
+
+/**
+ * Module dependencies.
+ */
+
+var cluster = require('../')
+ , http = require('http')
+ , connect = require('connect');
+
+// edit /etc/hosts
+// 127.0.0.1 foo.com
+// 127.0.0.1 bar.com
+
+var app = http.createServer(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 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');
+});
+
+cluster(server)
+ .use(cluster.debug())
+ .listen(80);
Please sign in to comment.
Something went wrong with that request. Please try again.