-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
executable file
·83 lines (69 loc) · 2.36 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/local/bin/node
/**
* Import express, our framework. and the route/business logic files
*/
var express = require('express');
var auth = require('connect-auth');
var mongoose = require('./schema.js').mongoose;
var routes = require('./routes');
var app = express.createServer()
// Mongoose (database) configuration
//var Note = mongoose.model( 'Note' );
//var User = mongoose.model( 'User' );
/**
* App configuration in three parts:
* - General configuration
* - Development specific config
* - Production specific config
*/
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
// app.use loads statements we want available to every route.
// We should put mongoose.connect here. but maybe we should only load models as needed in routes.
app.use(mongoose.connect('mongodb://localhost/kn'));
app.use(express.bodyParser({uploadDir:'./upload'}));
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({ secret: 'your secret here' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
console.dir(routes);
// console.dir(routes.notes);
app.get('/', routes.index);
// routes.notes is not found if stored in notes.js. Hmm
// notes will return a set of notes given a courseID
app.get('/searchBySchool', routes.searchBySchool);
app.get('/notesOfSchool/:school', routes.notesOfSchool);
app.post('/upload', routes.upload);
app.get('/notes/:course', routes.notes);
app.get('/schools', routes.schools);
/*app.get('/notes', function(req, res){
console.log('inside the note route');
console.log(Note);
Note.find({}).run( function( err, notes ){
if(err) console.log(err);
console.log('notes');
console.log(notes);
res.json(notes);
});
});
*/
// Exception Catch-All
process.on('uncaughtException', function (e) {
console.log("!! %%%%% Uncaught Exception\n" + e.stack);
});
app.listen(3000);
console.log("Express server listening on port %d in %s mode",
app.address().port, app.settings.env);
// I want to share the mongoose connection with routes
// not sure this is the ideal way
exports.mongoose = mongoose;