Skip to content

Instantly share code, notes, and snippets.

@ramsunvtech
Created November 28, 2015 14:30
Show Gist options
  • Save ramsunvtech/a0f1b8107449fb2f0728 to your computer and use it in GitHub Desktop.
Save ramsunvtech/a0f1b8107449fb2f0728 to your computer and use it in GitHub Desktop.
Vhost in NodeJS
var connect = require('connect'),
serveStatic = require('serve-static'),
vhost = require('vhost')
var mailapp = connect()
// add middlewares to mailapp for mail.example.com
// create app to serve static files on subdomain
var staticapp = connect()
staticapp.use(serveStatic('public'))
// create main app
var app = connect()
// add vhost routing to main app for mail
app.use(vhost('mail.example.com', staticapp));
var PORT = 80;
app.listen(PORT)
console.log('app listening to ', PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment