-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
75 lines (70 loc) · 2.21 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
var path = require('path');
var markdown = require('markdown-js');
var partials = require('express-partials');
var ejs = require('ejs');
var fs = require('fs');
var express = require('express');
var app = express();
var sign = require('./controllers/sign');
var config = require('./app_config').config;
var routes = require('./routes');
var expressValidator = require('express-validator');
var appRoot = './';
var passport = require('passport');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var flash = require('express-flash');
var http = require('http');
/**
* API keys and Passport configuration.
*/
var secrets = require('./config/secrets');
var passportConf = require('./config/passport');
app.configure('development', function() {
app.set('views', path.join(appRoot, 'views'));
app.set('views engine', 'html');
app.set('view cache', false);
app.engine('html', ejs.renderFile);
app.engine('md', function(path, options, fn) {
fs.readFile(path, 'utf8', function(err, str) {
if (err) return fn(err);
str = markdown.parse(str).toString();
fn(null, str);
});
});
app.use(express.bodyParser());
app.use(expressValidator([]));
app.use(express.cookieParser());
// app.use(express.session({secret: config.sessionSecret}));
// app.use(sign.authUser);
// app.use(sign.toobusy);
app.use(flash());
app.use(session({
resave: true,
saveUninitialized: true,
secret: secrets.sessionSecret,
store: new MongoStore({ url: secrets.db, autoReconnect: true })
}));
app.use(partials());
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(appRoot, 'public')));
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
});
// set static, dynamic helpers
app.locals({
config: config,
csrf: function(req, res) {
return req.session ? req.session._csrf : '';
}
});
routes(app);
// app.listen(config.port);
// console.log(config.host + ':' + config.port);
// app is a callback function or an express application
module.exports = app;
if (!module.parent) {
http.createServer(app).listen(config.port, function(){
console.log("Server listening on port " + config.port);
});
}