-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (82 loc) · 4.1 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
var session = require('express-session');
var express = require('express');
var multer = require('multer');
var mongoose = require('mongoose');
global.app = express();
var config = require(__dirname + '/config/config');
app.config = config;
var Database = require(__dirname + '/config/database.js')(app, mongoose);
var moment = require('moment');
var bodyParser = require('body-parser');
//Middlewares
var mwSession = require(__dirname + '/middlewares/session');
//Controllers
var cAuth = require(__dirname + '/controllers/auth.controller');
var cProfile = require(__dirname + '/controllers/profile.controller');
var cOrder = require(__dirname + '/controllers/order.controller');
var cHistory = require(__dirname + '/controllers/history.controller');
var cImport = require(__dirname + '/controllers/import.controller');
var cMenuManager = require(__dirname + '/controllers/admincp/menu-manager.controller.js');
var cStatisticsByDay = require(__dirname + '/controllers/admincp/statistics-by-day.controller.js');
var cUserManager = require(__dirname + '/controllers/admincp/user-manager.controller.js');
// Autoload Models
global.Server = { Model : {} };
require('fs').readdir(__dirname + '/models/', function(err, files) {
files.forEach(function(file) {
if (file.match(/\.js$/) !== null) {
var name = file.replace('.js', '');
global.Server.Model[name] = require(__dirname + '/models/' + file)(mongoose);
}
});
});
// App init
var upload = multer();
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.engine('jade', require('jade').__express);
app.use(session({
secret: '2359media',
resave: true,
saveUninitialized: true
}));
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.get('/', mwSession.getSessionData, function(req, res){
//res.locals.test_data = 123;
res.render('index', { data : req.currentData });
});
app.get('/login', cAuth.login);
app.get('/logout', cAuth.logout);
app.get('/gglogin', cAuth.gglogin);
app.get('/profile', mwSession.getSessionData, cProfile);
app.get('/order/:date', mwSession.getSessionData, cOrder.getMenuListByDay);
app.post('/order', mwSession.getSessionData, cOrder.orderFoodByDay);
app.get('/about', mwSession.getSessionData, function (req, res){
res.render('about', { data : req.currentData });
});
app.get('/history', mwSession.getSessionData, cHistory.viewHistory);
app.post('/history', mwSession.getSessionData, cHistory.loadMoreHistory);
app.get('/admincp/menu-manager', mwSession.getSessionData, cMenuManager.getMenuListByDay);
app.get('/admincp/menu-manager/delete/:id', mwSession.getSessionData, cMenuManager.deleteMenuById);
app.get('/admincp/menu-manager/edit/:id', mwSession.getSessionData, cMenuManager.getMenuById);
app.post('/admincp/menu-manager/edit/:id', mwSession.getSessionData, cMenuManager.editMenuById);
app.post('/admincp/menu-manager', mwSession.getSessionData, cMenuManager.getMenuListByDay);
app.get('/admincp/menu-importer', mwSession.getSessionData, cImport.getImport);
app.post('/admincp/menu-importer', mwSession.getSessionData, upload.single('xlfile'), cImport.postImport);
app.get('/admincp/statistics-by-day', mwSession.getSessionData, cStatisticsByDay.getStatisticsByDay);
app.post('/admincp/statistics-by-day', mwSession.getSessionData, cStatisticsByDay.getStatisticsByDay);
app.get('/admincp/user-manager', mwSession.getSessionData, cUserManager.getUser);
app.post('/admincp/user-manager', mwSession.getSessionData, cUserManager.getUser);
app.get('/admincp/user-manager/edit/:id', mwSession.getSessionData, cUserManager.getUserById);
app.post('/admincp/user-manager/edit/:id', mwSession.getSessionData, cUserManager.editUserById);
app.get('/test', mwSession.getSessionData,function (req, res){
});
module.exports.listen = app.listen(app.config.server.port, function(){
var host = this.address().address;
console.log('✔ App is listening at http://%s:%s', host, this.address().port);
});
module.exports.port = app.config.server.port;
module.exports = app;