-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
79 lines (68 loc) · 2.13 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
//Copyright (C) 2011 Ivan Torres -MrPix
/**
* Module dependencies.
*/
var express = require('express'),
Log = require('log'),
log = new Log(),
fs = require('fs'),
i18next = require('i18next'),
Db = require('mongodb').Db,
mongoStore = require('connect-mongodb'),
session_store,
port = process.env.PORT || 3000,
schedule = require('node-schedule');
Db.connect("mongodb://nominator:[email protected]:29257/nomination-sessions", function(err, db) {
session_store = new mongoStore({db: db});
});
var app = module.exports = express.createServer();
i18next.init({
ns: { namespaces: ['translation'], defaultNs: 'translation'}
});
// Configuration
app.configure('development', function() {
log.level = Log.DEBUG;
log.stream = fs.createWriteStream('logs/dev.log', {
flags: 'w'
});
port = 80; //cambiar a puerto deseado
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
app.configure('production', function() {
log.level = Log.NOTICE;
log.stream = fs.createWriteStream('/logs/prod.log', {
flags: 'w'
});
app.use(express.errorHandler());
});
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(i18next.handle);
app.use(express.methodOverride());
app.use(express.cookieParser()); // cookie parser
app.use(express.session({secret: 'nodejsMexico', store: session_store}));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
i18next.registerAppHelper(app)
.serveClientScript(app)
.serveDynamicResources(app);
// Routes
require('./routes/index')(app, log);
require('./routes/dashboard')(app, log);
//add process to kill old nomination
var rule = new schedule.RecurrenceRule();
rule.minute = 51;
schedule.scheduleJob(rule, function(){
console.log('The answer to life, the universe, and everything!');
});
if (!module.parent) {
app.listen(port);
console.log("Express server listening on port %d in %s mode",
app.address().port, app.settings.env);
}