Permalink
Browse files

Upgraded express to 3.x

  • Loading branch information...
1 parent fd422ff commit 37986074d43d2194f8e6c5f3234e9a7f1c88ede4 @mikevalstar committed Sep 30, 2012
Showing with 1,032 additions and 987 deletions.
  1. +12 −12 addUser.js
  2. +31 −24 app.js
  3. +228 −228 lib/AdminPages.js
  4. +44 −44 lib/Database.js
  5. +55 −55 lib/ErrorHandler.js
  6. +137 −137 lib/PublicPages.js
  7. +20 −20 lib/StaticPages.js
  8. +57 −57 lib/Util.js
  9. +2 −1 package.json
  10. +6 −2 views/404.jade
  11. +33 −29 views/about.jade
  12. +9 −5 views/admin/index.jade
  13. +24 −20 views/admin/login.jade
  14. +26 −22 views/admin/post.jade
  15. +26 −22 views/admin/postlist.jade
  16. +48 −48 views/error.jade
  17. +60 −56 views/index.jade
  18. +53 −52 views/layout.jade
  19. +44 −40 views/post.jade
  20. +9 −5 views/projects.jade
  21. +108 −108 views/rss2.0.template.jade
View
@@ -16,17 +16,17 @@ var db = new Database();
db.connect('mongodb://localhost/mv');
if(process.argv.length == 4){
- // 0 will be node, 1 will be the script
-
- var au = db.model('adminUser');
- var usr = new au({login: process.argv[2], password: hashString(process.argv[3]) });
- usr.save(function(err){
- console.log("User added to database");
- process.exit(0); // Success
- });
-
+ // 0 will be node, 1 will be the script
+
+ var au = db.model('adminUser');
+ var usr = new au({login: process.argv[2], password: hashString(process.argv[3]) });
+ usr.save(function(err){
+ console.log("User added to database");
+ process.exit(0); // Success
+ });
+
}else{
- console.error("Script requires exactly 2 arguments");
- console.error("Usage: node addUser.js <email> <password>");
- process.exit(1); // Failure
+ console.error("Script requires exactly 2 arguments");
+ console.error("Usage: node addUser.js <email> <password>");
+ process.exit(1); // Failure
}
View
@@ -3,39 +3,45 @@
*/
process.env.TZ = 'GMT';
var express = require('express')
- , mongoStore = require('session-mongoose');
-
-var app = module.exports = express.createServer();
+ , http = require('http')
+ , path = require('path')
+ , mongoStore = require('session-mongoose');
+
+var app = express();
// Configuration
app.configure(function(){
- app.set('views', __dirname + '/views');
- app.set('view engine', 'jade');
- app.use(express.bodyParser());
- app.use(express.methodOverride());
- app.use(express.cookieParser());
-
- var mongooseSessionStore = new mongoStore({
- url: "mongodb://localhost/mv",
- interval: 1200000
- });
-
- app.use(express.session( {cookie: {maxAge: 1200000}, store: mongooseSessionStore, secret: "mv secret" }));
- app.use(app.router);
- app.use(express.static(__dirname + '/htdocs'));
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(express.cookieParser());
+ app.use(require('less-middleware')({ src: __dirname + '/htdocs' }));
+
+ var mongooseSessionStore = new mongoStore({
+ url: "mongodb://localhost/mv",
+ interval: 1200000
+ });
+
+ app.use(express.session( {cookie: {maxAge: 1200000}, store: mongooseSessionStore, secret: "mv secret" }));
+ app.use(app.router);
+ app.use(express.static(path.join(__dirname, 'htdocs')));
});
// Error Handling
var error = require('./lib/ErrorHandler');
app.configure('development', function(){
//app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
- app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
+ app.set('port', process.env.PORT || 3000);
+ app.use(express.logger('dev'));
+ app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
});
app.configure('production', function(){
//app.use(express.errorHandler());
- app.use(error());
+ app.set('port', process.env.PORT || 80);
+ app.use(error());
});
// Database
@@ -58,18 +64,19 @@ pp.initPages(app, db);
// 404 Page
app.use(function(req, res, next){
- res.render('404.jade', {title: "404 - Page Not Found", showFullNav: false, status: 404, url: req.url });
+ res.render('404.jade', {title: "404 - Page Not Found", showFullNav: false, status: 404, url: req.url });
});
// Example error pages
app.get('/ErrorExample', function(req, res, next){
- next(new Error('keyboard cat!')); // trigger an error
+ next(new Error('keyboard cat!')); // trigger an error
});
app.get('/ErrorExample2', function(req, res){
- res.render('404.jade'); // force an error.. we did not set the title
+ res.render('404.jade'); // force an error.. we did not set the title
});
-app.listen(3000);
-console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+http.createServer(app).listen(app.get('port'), function(){
+ console.log("Express server listening on port %d in %s mode.\n", app.get('port'), app.settings.env);
+});
Oops, something went wrong. Retry.

0 comments on commit 3798607

Please sign in to comment.