-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
79 lines (56 loc) · 2.01 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
'use strict';
var express = require('express');
var argv = require('optimist').argv;
var seneca = require('seneca')();
require('express-expose');
process.on('uncaughtException', function(err) {
console.error('uncaughtException:', err.message);
console.error(err.stack);
process.exit(1);
});
seneca.use('options', argv.options || 'options.mine.js');
var options = seneca.export('options');
seneca.use('./lib/douitsu', options);
seneca.ready(function(err){
if( err ) { return process.exit( !console.error(err) ); }
var web = seneca.export('web');
seneca.act('role:settings, cmd:define_spec, kind:user',{spec:options.settings.spec});
var app = express();
app.engine('ejs',require('ejs-locals'));
app.set('views', __dirname + '/views');
app.set('view engine','ejs');
app.use( express.cookieParser() );
app.use( express.query() );
app.use( express.bodyParser({uploadDir: __dirname + '/public/uploads', keepExtensions: true}) );
app.use( express.methodOverride() );
app.use( express.json() );
app.use( express.session({secret:'seneca', store: seneca.export('douitsu/session-store')}) );
app.use( web );
// Disable signup and account features if LDAP is enabled
if (options.auth.ldap.enabled) {
options.features.signup = false;
options.features.account = false;
}
app.expose(options.features, 'features', 'features');
app.expose(options.theme.locale, 'locale', 'locale');
app.use(function(req,res,next){
var lang = req.acceptedLanguages || ['en'];
res.expose(lang, 'languages', 'languages');
next();
});
app.use(function(req,res,next){
res.locals.theme = options.theme;
next();
});
require('./routes')({options:options, seneca:seneca, app:app});
app.use( express.static(__dirname+options.main.public) );
seneca.log.info('listen',options.main.port);
app.listen( options.main.port );
if (options.listen && options.listen.port) {
seneca.listen( options.listen.port );
}
else {
seneca.listen();
}
seneca.export('douitsu/init-store')();
});