reorganized assets, completed new header
[oweals/finalsclub.git] / app.js
diff --git a/app.js b/app.js
index 62c543cb4567a6e669d45c3f8ed5577cd99d6442..80a05910fb58551b94f918af4c42e991facf5941 100644 (file)
--- a/app.js
+++ b/app.js
@@ -22,7 +22,7 @@ var hat                                       = require('hat');
 var connect                    = require( 'connect' );
 var Session                    = connect.middleware.session.Session;
 var parseCookie = connect.utils.parseCookie;
-var Backchannel = require('../bc/backchannel');
+var Backchannel = require('./bc/backchannel');
 
 // Depracated
 // Used for initial testing
@@ -134,6 +134,7 @@ app.configure(function(){
   // Sessions are stored in mongodb which allows them
   // to be persisted even between server restarts.
   app.set( 'sessionStore', new mongoStore( {
+    'db' : 'fc',
     'url' : app.set( 'dbUri' )
   }));
 
@@ -162,13 +163,8 @@ app.configure(function(){
   app.use( app.router );
 
   app.use(express.logger({ format: ':method :url' }));
-  // This is the errorHandler set in configuration earlier
-  // being set to a variable to be used after all other
-  // middleware is loaded. Error handling should always
-  // come last or near the bottom.
-  var errorHandler = app.set( 'errorHandler' );
-
-  app.use( errorHandler );
+  // This is the command to use the default express error logger/handler
+  app.use(express.errorHandler({ dumpExceptions: true }));
 });
 
 
@@ -493,7 +489,11 @@ app.get( '/schools', checkAjax, loadUser, function( req, res ) {
       // If schools are found, loop through them gathering any courses that are
       // associated with them and then render the page with that information.
       sendJson(res, { 'user': user.sanitized, 'schools' : schools.map(function(school) {
-        return school.sanitized;
+        var s = school.sanitized;
+        s['courses'] = Course.find( { 'school' : s._id } ).sort( 'name', '1' ).run(function( err, courses) {
+            return courses.map( function(c) { return c.sanitized; } );
+        });
+        return s
       })})
     } else {
       // If no schools have been found, display none
@@ -1452,7 +1452,7 @@ function loadSubject( req, res, next ) {
   if( url.parse( req.url ).pathname.match(/subject/) ) {
     ArchivedSubject.findOne({id: req.params.id }, function(err, subject) {
       if ( err || !subject) {
-        sendJson(res,  {status: 'error', message: 'Subject with this ID does not exist'} )
+        sendJson(res,  {status: 'not_found', message: 'Subject with this ID does not exist'} )
       } else {
         req.subject = subject;
         next()
@@ -1467,7 +1467,7 @@ function loadOldCourse( req, res, next ) {
   if( url.parse( req.url ).pathname.match(/course/) ) {
     ArchivedCourse.findOne({id: req.params.id }, function(err, course) {
       if ( err || !course ) {
-        sendJson(res,  {status: 'error', message: 'Course with this ID does not exist'} )
+        sendJson(res,  {status: 'not_found', message: 'Course with this ID does not exist'} )
       } else {
         req.course = course;
         next()
@@ -1818,8 +1818,8 @@ process.on('uncaughtException', function (e) {
 
 // Launch
 
-mongoose.connect( app.set( 'dbUri' ) );
-mongoose.connection.db.serverConfig.connection.autoReconnect = true
+// mongoose now exepects a mongo url
+mongoose.connect( 'mongodb://localhost/fc' ); // FIXME: make relative to hostname
 
 var mailer = new Mailer( app.set('awsAccessKey'), app.set('awsSecretKey') );