-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
128 lines (94 loc) · 2.83 KB
/
index.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*** DEPENDENCIES ***/
var express = require('express');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var app = express();
//Passport
var passport = require('passport');
var flash = require('connect-flash');
var LocalStrategy = require('passport-local').Strategy;
//User Variable
var users = require('./app/scripts/models/user');
var User = require('mongoose').model('User');
//ToDo Variable
var tasks = require('./app/scripts/models/task');
var Task = require('mongoose').model('Task');
/*** DB ***/
var MONGOHQ_URL="mongodb://"+process.env.MONGOHQ_UN+":"+process.env.MONGOHQ_PW+"@candidate.21.mongolayer.com:11484,candidate.33.mongolayer.com:11614/app29663006";
var MONGOLOCAL_URL="mongodb://localhost/blocitoff"
mongoose.connect(process.env.NODE_ENV === 'production' ? MONGOHQ_URL : MONGOLOCAL_URL);
app.use(session({
resave: true,
saveUninitialized: true,
extended: true,
secret: "foo",
}));
/***CONFIGURATIONS***/
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
/***PRODUCTION/DEV ROUTES***/
if(process.env.NODE_ENV === 'production'){
app.get('/*', express.static(__dirname + '/dist'));
}
else{
app.get('/*', express.static(__dirname + '/.tmp'));
app.get('/*', express.static(__dirname + '/app'));
app.get('/*', express.static(__dirname + '/'));
}
app.get('/#/*', function(req, res){
res.sendfile('./app/index.html');
});
/***ROUTES & FUNCTIONS***/
//Passport
require('./app/scripts/passport')();
//ToDo routes
require('./app/scripts/routes/task')(app);
//User routes
require('./app/scripts/routes/user')(app);
/***Tasks Archive After 7 Days***/
Task.find({}, function (err, todos){
var seconds = Date.now();
var week = 604800000; //604800000 = 1 week
console.log(todos);
for (i=0; i < todos.length; i++) {
var date = new Date(todos[i].date);
var datems = date.getTime();
if ((datems + week) < seconds) {
todos[i].status = "archive"
todos[i].save(function(err) {
if (err) { return next(err); }
});
}
}
});
Task.find({}, function (err, todos){
setInterval(function() {
var seconds = Date.now();
var week = 604800000; //604800000 = 1 week
console.log(todos);
for (i=0; i < todos.length; i++) {
var date = new Date(todos[i].date);
var datems = date.getTime();
if ((datems + week) < seconds) {
todos[i].status = "archive"
todos[i].save(function(err) {
if (err) { return next(err); }
});
}
}
}, 3600000);//3600000 = 1 hour
});
/*** LOCAL SERVER ***/
if(process.env.NODE_ENV !== 'production'){
app.listen(1337);
} else {
var port = process.env.PORT || CONFIG.port;
app.listen(port);
}