Skip to content

Instantly share code, notes, and snippets.

@mikevalstar
Created November 11, 2011 18:55
Show Gist options
  • Save mikevalstar/1358857 to your computer and use it in GitHub Desktop.
Save mikevalstar/1358857 to your computer and use it in GitHub Desktop.
/**
* Module dependencies.
*/
var express = require('express');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/htdocs'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Internal Page Handlers
var static_pages = require('./lib/StaticPages');
var sp = new static_pages();
sp.initPages(app);
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
h2 Blog
p some sample content
!!! 5
html(lang="en")
head
title #{title} - Sample Website
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='http://code.jquery.com/jquery-1.7.min.js', type='text/javascript')
//if lt IE 9
script(src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js")
body#sample
#O
h1 My Sample Website
#CC!= body
#F Sample © 2011
var StaticPages = module.exports = function StaticPages(){};
StaticPages.prototype = {
initPages: function(app){
// Routes
app.get('/', function(req, res){
res.render('index', {
title: 'Home'
});
});
app.get('/Blog', function(req, res){
res.render('index', {
title: 'Blog'
});
});
app.get('/About', function(req, res){
res.render('about', {
title: 'Home'
});
});
}
};
...
app.get('/Blog/:id/:title', function(req, res){
res.render('post/bp_' + req.params.id , {
title: req.params.title.replace(/_/g,' ')
});
});
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment