-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.js
100 lines (84 loc) · 2.42 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
require('dotenv').config();
const express = require('express'),
Liquid = require('liquidjs'),
engine = Liquid(),
moment = require('moment'),
session = require('express-session'),
sessionStore = require('connect-mongo')(session),
path = require('path'),
flash = require('flash'),
compression = require('compression'),
favicon = require('serve-favicon'),
config = require('./config/development'),
bodyParser = require('body-parser'),
mongoose = require('mongoose');
// Libs
mongoose.connect(config.MONGO_DB.URI, function (err) {
if (err) {
console.log(err);
return process.exit(0);
}
engine.registerFilter('remove', function (v, args) {
let arr = [],
arg_arr = args.split(',');
//remove
for (let _arg of arg_arr) {
for (let k in v) {
if (k == _arg) delete v[k];
}
}
//build http query
for (k in v) {
arr.push([k, '=', v[k]]).join('');
}
return arr.join('&');
});
engine.registerFilter('sum', function (v) {
if (!v) return 0;
return v.reduce(function (a, b) {
return a + b;
}, 0);
});
engine.registerFilter('format', function (v) {
if (!v) {
return 0;
}
return v.toLocaleString();
});
//config
const app = express();
app.listen(process.env.PORT || 3000);
//middlewavers
// const sess = {
// secret: 's1asfas53qedw',
// maxAge: 3600000 * 24 * 365,
// store: new sessionStore({
// db: DBO(),
// ttl: 3600000 * 24 * 365,
// }),
// resave: false,
// saveUninitialized: false
// }
//app.use(session(sess));
app.engine('liquid', engine.express());
app.set('view engine', 'liquid');
app.set('view engine', 'liquid');
app.set('views', __dirname + '/public');
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
app.use(flash());
app.use(compression());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(__dirname + '/public'));
//app.use(acl());
// Routes
//require('./app/controllers/admin/index.js')(app);
//require('./app/controllers/user/index.js')(app);
// No matching route
app.use(function(err, req, res, next) {
res.status(err.status || 500);
// todo: log err.message
console.log(err.message);
res.end();
//res.render('error');
});
});