-
Notifications
You must be signed in to change notification settings - Fork 23
/
config.js
65 lines (56 loc) · 1.66 KB
/
config.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
/*
Configuration File
Author : Shane Doyle
Date : 16/09/2012
This file is used to store the configuration
settings for the application.
*/
module.exports = function(app, express, mongoose){
var config = this;
app.configure(function(){
app.set("views", __dirname + "/views");
app.set("view engine", "jade");
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({secret: "crazysecretstuff", logged: false, originalRoute: ""}));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + "/public"));
});
// Development Configuration
app.configure("development", function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.mongoose.connect("mongodb://localhost/quizBank");
});
// Production Configuration
app.configure("production", function(){
app.use(express.errorHandler());
// app.mongoose.connect("mongodb://flame.mongohq.com:27087/quizBank");
});
app.use(NotFoundErrorHandler);
app.use(ErrorHandler);
// Error Handling - Not Found
function NotFound(msg) {
this.name = "NotFound";
Error.call(this, msg);
Error.captureStackTrace(this, arguments.callee);
}
// Error Handling - 404 Error
function NotFoundErrorHandler(err, req, res, next) {
if (error instanceof NotFound) {
res.render("404.jade", {
status: 400
});
} else {
next(error);
}
}
// Error Handling - 500 Error
function ErrorHandler(err, req, res, next) {
res.render("500.jade", {
status: 500,
locals: {error: err}
});
}
return config;
};