Skip to content

Commit

Permalink
update to express 4
Browse files Browse the repository at this point in the history
  • Loading branch information
twalker committed Apr 12, 2014
1 parent c6b1ccb commit 719439d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 239 deletions.
55 changes: 26 additions & 29 deletions app.js
@@ -1,12 +1,9 @@
var express = require('express'),
routes = require('./routes'),
eggs = require('./routes/eggs'),
mocki = require('./routes/mocki'),
http = require('http'),
path = require('path'),
stylus = require('stylus'),
nib = require('nib'),
pkg = require('./package.json');
var express = require('express')
, http = require('http')
, path = require('path')
, stylus = require('stylus')
, nib = require('nib')
, pkg = require('./package.json');

var app = module.exports = express();

Expand All @@ -16,36 +13,36 @@ app
.set('view engine', 'jade')
.set('name', pkg.name)
.set('version', pkg.version)
.use(express.favicon('public/img/favicon.ico'))
.use(express.logger('dev'))
.use(app.router)
// use mock json files for api requests
.use('/api', mocki())
.use(require('static-favicon')('public/img/favicon.ico'))
.use(require('morgan')('dev'))
.use(stylus.middleware({
src: path.join(__dirname, 'public'),
compile: compileCss
compile: function compileCss(str, path) {
return stylus(str)
.set('filename', path)
.set('compress', true)
.use(nib());
}
}))
.use(express.static(path.join(__dirname, 'public')));

app.configure('development', function(){
app.use(express.errorHandler());
// spa home view -- routing handled w/pushState on the client
app.get('/', function(req, res){
res.render('index', { title: require('./package.json').name });
});

// spa
app.get('/', routes.index);

// client-tests
app.get('/client-tests/:name?', require('./routes/client-tests').show);
//app.get('/client-tests/:name?', require('./routes/client-tests').show);
app.use('/client-tests', require('./routes/client-tests'));

// manual routes to egg resources
//app.get('/api/eggs', eggs.list);
//app.put('/api/eggs/:id', eggs.update);
// use mock json files for api requests
app.use('/api',require('mocki')(path.join(__dirname, 'test', 'fixtures')))
// OR, manual api routes to egg resources (when not using mocki)
//app.use('/api', require('./routes/eggs'))

function compileCss(str, path) {
return stylus(str)
.set('filename', path)
.set('compress', true)
.use(nib());
// error handling
if('production' !== app.get('env')){
app.use(require('errorhandler')({ dumpExceptions: true, showStack: true }));
}

http.createServer(app).listen(app.get('port'), function(){
Expand Down
4 changes: 2 additions & 2 deletions bower.json
@@ -1,6 +1,6 @@
{
"name": "eggshell",
"version": "0.0.8",
"version": "0.0.11",
"ignore": [
"**/.*",
"node_modules",
Expand All @@ -22,4 +22,4 @@
"chai": "1.9.1",
"sinonjs": "1.9.0"
}
}
}
35 changes: 20 additions & 15 deletions package.json
@@ -1,40 +1,45 @@
{
"name": "eggshell",
"version": "0.0.9",
"version": "0.0.11",
"private": true,
"dependencies": {
"express": "~3.5.0",
"jade": "~1.3.0",
"stylus": "~0.42.3",
"express": "~4.0.0",
"body-parser": "^1.0.1",
"morgan": "^1.0.0",
"static-favicon": "^1.0.2",
"errorhandler": "^1.0.0",
"jade": "~1.3.1",
"stylus": "~0.43.1",
"nib": "~1.0.2"
},
"devDependencies": {
"mocki": "git://github.com/twalker/mocki.git#0.4.2",
"mocha": "~1.18.2",
"chai": "~1.9.1",
"supertest": "~0.10.0",
"cuid": "~1.2.1",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-stylus": "~0.13.2",
"grunt-contrib-stylus": "~0.14.0",
"grunt-contrib-requirejs": "~0.4.3",
"grunt-contrib-jshint": "~0.9.2",
"grunt-contrib-jshint": "~0.10.0",
"grunt-notify": "~0.2.20",
"grunt-bumpup": "~0.5.2",
"bower": "~1.3.1",
"bower": "~1.3.2",
"matchdep": "*",
"gulp": "~3.5.6",
"gulp": "~3.6.0",
"gulp-util": "~2.2.14",
"gulp-livereload": "~1.2.0",
"gulp-stylus": "0.1.0",
"gulp-livereload": "~1.3.1",
"gulp-stylus": "0.2.0",
"tiny-lr": "0.0.5",
"gulp-watch": "~0.5.3",
"gulp-jshint": "~1.5.1",
"gulp-watch": "~0.5.4",
"gulp-jshint": "~1.5.3",
"jshint-stylish": "~0.1.5",
"gulp-requirejs": "~0.1.3",
"gulp-uglify": "~0.2.1",
"gulp-clean": "~0.2.4",
"gulp-bump": "~0.1.6",
"gulp-notify": "~1.2.4"
"gulp-bump": "~0.1.7",
"gulp-notify": "~1.2.5"
},
"scripts": {
"test": "mocha --ui bdd --recursive --reporter nyan --timeout 10000 --slow 300",
Expand All @@ -44,4 +49,4 @@
"start-prod": "NODE_ENV=production pm2 start app.js --name eggshell -i max",
"stop-prod": "pm2 stop eggshell"
}
}
}
8 changes: 1 addition & 7 deletions public/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions routes/client-tests.js
@@ -1,10 +1,12 @@
/*
client-tests shows a client-side unit test, and links to others.
*/
var fs = require('fs'),
path = require('path');
var fs = require('fs')
, path = require('path')
, express = require('express')
, router = express.Router();

exports.show = function(req, res){
var show = function show(req, res){
var testpath = path.join(__dirname, '..', 'public/js/test');
fs.readdir(testpath, function(err, files){
var rexJsExt = /\.js$/;
Expand All @@ -18,3 +20,7 @@ exports.show = function(req, res){
res.render('client-tests', {name: req.params.name, names: testFiles});
});
};

router.get('/:name?', show);

module.exports = router;
17 changes: 13 additions & 4 deletions routes/eggs.js
@@ -1,19 +1,28 @@
/*
* Serves eggs for Backbone consumption.
*
*/
var express = require('express');
var bodyParser = require('body-parser');
var router = express.Router();

var eggs = [
{id: 0, name: 'brown', cracked: false},
{id: 1, name: 'blue', cracked: false},
{id: 2, name: 'green', cracked: false}
];

exports.list = function(req, res){
var list = function list(req, res){
res.json(eggs);
};

exports.update = function(req, res) {
var update = function update(req, res) {
var json = req.body;
eggs[json.id] = json;
console.log('%s egg updated', json.name);
};
};

router.use(bodyParser.json());
router.put('/eggs/:id', update);
router.get('/eggs', list);

module.exports = router;
8 changes: 0 additions & 8 deletions routes/index.js

This file was deleted.

0 comments on commit 719439d

Please sign in to comment.