clarkk
clarkk

Reputation: 1

How to initialize nowjs on express with virtual hosts

I need to initialize nowjs on this express server with vhosts.. How do I do that?

var host_api = express()
    .get('/', function(req, res){

    });

var host_secure = express()
    .get('/', function(req, res){

    });

express()
    .use(vhost('api.domain.com', host_api))
    .use(vhost('secure.domain.com', host_secure))
    .listen(3000);

Initialize nowjs on simple http

var http = require('http'),
    nowjs = require('now');
httpServer = http.createServer(function (req, res) {
  res.send('Hello World\n');
});
httpServer.listen(3000);

var everyone = nowjs.initialize(httpServer);

Upvotes: 0

Views: 223

Answers (1)

ItalyPaleAle
ItalyPaleAle

Reputation: 7332

Connect (on which Express is built) includes the required code to run vhosts.

You can see the documentation here: http://www.senchalabs.org/connect/vhost.html
For example:

connect() // Or "app" if app is an express application (see example below)
  .use(connect.vhost('foo.com', fooApp))
  .use(connect.vhost('bar.com', barApp))
  .use(connect.vhost('*.com', mainApp))

Each "app" (fooApp, barApp, mainApp) is either a Node.js HTTP server or a Connect/Express app. You can create each app into a separate js file, and then include it:

var fooApp = require('foo/app.js').app

An example can be seen here: http://www.jondev.net/articles/vHosts_with_Node.JS_and_Express

Upvotes: 0

Related Questions