http - Subdomains in Node.js with Express for Nodejitsu -


i'd set subdomains node.js app. i've built site express.js, , i'd throw little web tool on subdomain of site. i've tried using vhost middleware little luck, open other approaches.

any rock!

ideally, drop new express app in sub directory change few lines of code, maybe change dns settings @ work. reason i'd can reuse fresh instance of stylus , jade new layouts , css styles , forth.

here's normal app.js, commented line attempt use vhost.

var express = require('express'),     routes = require('./routes');  var app = module.exports = express.createserver();  // configuration app.configure(function() {   app.set('views', __dirname + '/views');   app.set('view engine', 'jade');   app.set('view options', { layout: false });   app.use(express.bodyparser());   app.use(express.methodoverride());   app.use('/courses', function (req, res, next) {     var privates = require('./.private.json'),         couch = require('nano')('https://' + privates.dbcreds.username + ':' + privates.dbcreds.password + '@wamoyo.iriscouch.com/');    });   app.use(require('stylus').middleware({     src: __dirname + '/public'   }));   app.use(app.router);   app.use(express.static(__dirname + '/public'));   // vhost - subdomain   // app.use(express.vhost('adventures.innovationbound.com', require('./adventures/index').app));   app.use(function (req, res, next) {     res.status(404);     res.render('four', {       title: "innovation bound",       now: new date().getfullyear()     });   });   app.use(function (err, req, res, next){     console.error(err.stack);     res.send(500, 'something broke!');   }); });  app.configure('development', function() {   app.use(express.errorhandler({     dumpexceptions: true,     showstack: true   })); });  app.configure('production', function() {   app.use(express.errorhandler()); });  // routes app.get('/', routes.index); app.get('/about', routes.about); app.get('/services', routes.services); app.get('/events', routes.events); app.get('/blog', routes.blog); app.post('/contact', routes.contact);  // courses // app.get('/heartbeat', routes.heartbeat); app.get('/courses', routes.courses);  // tools app.get('/point', routes.point);  app.listen(3000, function() {   console.log("express server listening on port %d in %s mode", app.address().port, app.settings.env); }); 

this using express 2.5, wouldn't mind migrating on 3 if need be.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -