Skip to content

Commit

Permalink
basic express + handlebars app:
Browse files Browse the repository at this point in the history
  • Loading branch information
mbernst committed Jan 21, 2014
1 parent 9db1fc2 commit c526cce
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node server.js
41 changes: 41 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

/**
* Module dependencies.
*/

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var handlebars = require('express3-handlebars')

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', handlebars({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');

app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser('Intro HCI secret key'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "IntroHCI",
"version": "0.0.1",
"author": "Intro HCI Staff",

"repository": {
"type": "git",
"url": "https://github.com/IntroHCI/lab4"
},
"license": "MIT",

"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.x",
"express3-handlebars": "*",
"mongodb": "*",
"mongoose": "*"
},
"engines": {
"node": "0.10.x"
}
}
8 changes: 8 additions & 0 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
color: #00B7FF;
}
8 changes: 8 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/*
* GET home page.
*/

exports.index = function(req, res){
res.render('index', { title: 'Intro to HCI' });
};
8 changes: 8 additions & 0 deletions routes/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/*
* GET users listing.
*/

exports.list = function(req, res){
res.send("respond with a resource");
};
1 change: 1 addition & 0 deletions views/index.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Example homepage</h1>
12 changes: 12 additions & 0 deletions views/layouts/main.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>{{{title}}}</title>
</head>
<body>

{{{body}}}

</body>
</html>

0 comments on commit c526cce

Please sign in to comment.