Skip to content

Instantly share code, notes, and snippets.

@naholyr
Created May 27, 2011 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naholyr/995588 to your computer and use it in GitHub Desktop.
Save naholyr/995588 to your computer and use it in GitHub Desktop.
Embedding another application with Express
var express = require('express')
var app = express.createServer()
// Configuration
app.configure(function() {
this.set('views', __dirname + '/views')
.set('view engine', 'jade')
.use(express.static(__dirname + '/public'))
.set('view options', {title: 'Express'})
})
.configure('development', function(){
this.use(express.errorHandler({ dumpExceptions: true, showStack: true }))
})
.configure('production', function(){
app.use(express.errorHandler())
})
// Routes
app.get('/', function(req, res){
res.render('index');
})
// Sub-application
app.use('/forum', require('forum').set('view options', {
title: app.set('view options').title,
layout: app.set('views') + '/layout.' + app.set('view engine'),
rootUrl: '/forum/'
}))
// Start server
app.listen(8080);
console.log("Express server listening on port %d", app.address().port);
h1= title
p Welcome to #{title}
p
a(href="/forum") Forum
!!!
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body!= body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment