-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
84 lines (68 loc) · 2.45 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
84
/**
* Module dependencies.
*/
process.env.TZ = 'GMT';
var express = require('express')
, 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({ keepExtensions: true, uploadDir: __dirname + "/tmp" }));
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.compress());
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.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.set('port', process.env.PORT || 80);
app.use(error());
});
// Database
var Database = require('./lib/Database');
var db = new Database();
db.connect('mongodb://localhost/mv');
// Internal Page Handlers
var static_pages = require('./lib/StaticPages');
var sp = new static_pages();
sp.initPages(app);
var admin_pages = require('./lib/AdminPages');
var ap = new admin_pages();
ap.initPages(app, db);
var public_pages = require('./lib/PublicPages');
var pp = new public_pages();
pp.initPages(app, db);
// 404 Page
app.use(function(req, res, next){
res.status(404);
res.render('404.jade', {title: "404 - Page Not Found", url: req.url });
});
// Example error pages
app.get('/ErrorExample', function(req, res, next){
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
});
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);
});