-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
106 lines (91 loc) · 3.2 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
96
97
98
99
100
101
102
103
104
105
106
require('dotenv').config();
const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const cron = require('node-cron');
const args = process.argv.slice(2);
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(session({
secret: process.env.SECRET ? process.env.SECRET : 'aptdevtempsecret',
cookie: {maxAge: 7 * 24 * 60 * 60 * 1000}, // expire in 7 day
resave: true,
saveUninitialized: true
}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
const event = require('./routes/event/event');
const event_api = require('./routes/event/event_api');
//const event_db = require("./server/event_db");
app.use('/event', event);
app.use('/event', event_api);
const index = require('./routes/index/index');
const user_api = require('./routes/index/user_api');
//const user_db = require("./server/user_db");
app.use('/', index);
app.use('/', user_api);
const contact_api = require('./routes/index/contact_api');
app.use('/contact', contact_api);
const project = require('./routes/project/project');
const project_api = require('./routes/project/project_api');
//const project_db = require('./server/project_db');
app.use('/project', project);
app.use('/project', project_api);
const proposal = require('./routes/proposal/proposal');
const proposal_api = require('./routes/proposal/proposal_api');
//const proposal_db = require('./server/proposal_db');
app.use('/proposal', proposal);
app.use('/proposal', proposal_api);
const user_db = require('./server/user_db');
cron.schedule('59 23 * * 6', function() { // run at midnight every Saturday
user_db.getUnconfirmedUsers(function(err, users) {
if (err) {
console.log(err);
} else {
let limitDate = new Date(); // get current date
limitDate.setDate(limitDate.getDate() - 10); // go 10 days before current date
// remove all users with unconfirmed emails created before limit date
for (let user of users) {
if (limitDate > user.create_date.getDate()) {
user_db.removeUser(user.id, function(err) {
if (err) {
console.log(err);
}
})
}
}
}
})
});
// catch 404 and forward to error handler
app.use(function (req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
if (process.env.INSTALL === 'yes' || args[0] === 'install') {
db.reset(function (err) {
if (err)
console.log(err);
});
}
module.exports = app;