-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
95 lines (77 loc) · 2.75 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
85
86
87
88
89
90
91
92
93
94
95
/**
* Module dependencies.
*/
var express = require('express');
var http = require('http');
var path = require('path');
var url = require('url');
var engine = require('ejs-locals');
var flash = require('connect-flash');
var Bootloader = require('./bootloader');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var Membership = require('./middleware/membership');
var RedisStore = require('connect-redis')(express);
var ImageDAL = require('./app/dal/imageDAL');
var imageDal = new ImageDAL();
var app = express();
var membership = new Membership(passport, LocalStrategy);
/**
* main application configuration.
*/
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.use(express.favicon(__dirname + '/public/images/favicon.ico'));
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/app/views/');
app.set('view engine', 'html');
app.set('layout', 'layout');
app.engine('html', require('ejs').renderFile);
app.locals({_layoutFile: true});
require('express-helpers')(app);
app.use(function (req, res, next) {
res.locals.req = req;
next();
});
app.use(function(req, res, next){
res.locals.path = url.parse(req.url).pathname;
next();
});
app.use(express.logger('dev'));
app.use(express.cookieParser('1234567890QWERTY'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({store: new RedisStore(), secret: '1234567890QWERTY'}));
app.use(express.errorHandler());
app.use(require('./middleware/deviceHandler'));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function(req, res, next){
res.locals.flash = req.flash('flash');
next();
});
app.use(app.router);
});
/**
* boot application with all modules.
*/
var bootloader = new Bootloader(app);
/**
* ERROR MANAGEMENT
* -------------------------------------------------------------------------------------------------
* error management - instead of using standard express / connect error management, we are going
* to show a custom 404 / 500 error using ejs and the middleware errorHandler (see ./middleware/errorHandler.js)
**/
var errorOptions = { dumpExceptions: true, showStack: true }
app.configure('development', function () { });
app.configure('production', function () {
errorOptions = {};
});
app.use(require('./middleware/errorHandler')(errorOptions));
/**
* Run server.
*/
var server = http.createServer(app).listen(app.get('port'), function(){
console.log("\n microscope server listening on port " + app.get('port'));
});