-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
105 lines (82 loc) · 3.35 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
/*jshint node: true */
// ładujemy wykorzystywane moduły
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var cookieSession = require('cookie-session');
var logger = require('morgan');
var errorHandler = require('errorhandler');
var cookieParser = require('cookie-parser');
var app = express();
var httpServer = require("http").Server(app);
var io = require("socket.io")(httpServer);
// tworzymy i konfigurujemy obiekt aplikacji
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mat2tab-logs');
//Models
var logModel = require('./models/log.js')(mongoose);
var auditLogModel = require('./models/auditLog.js')(mongoose);
var tokenSecurity = require('./models/tokenSecurity.js')(mongoose);
var user = require('./models/user.js')(mongoose);
var notification = require('./models/notification.js')(mongoose);
//Controllers API
var logControllerApi = require('./api/logController.js')(logModel, auditLogModel, tokenSecurity,notification);
var tokenSecurityControllerApi = require('./api/tokenSecurityController.js')(tokenSecurity);
var authControllerApi = require('./api/authController.js')(user);
var notifyControllerApi = require('./api/notifyController.js')(notification);
//Controllers WEB
var logController = require('./web/logController.js')();
var authController = require('./web/authController.js')();
var tokenSecurityController = require('./web/tokenSecurityController.js')();
var notifyController = require('./web/notifyController.js')();
var port = process.env.PORT || 3000;
var env = process.env.NODE_ENV || 'development';
var secret = process.env.SECRET || '$uper $ecret';
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
// obsługa danych typu application/json
app.use(bodyParser.json());
// obsługa danych typu application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// obsługa sesji za pomocą ciasteczek
app.use(cookieSession({secret: secret}));
// „middleware” obsługujące LESS-a
app.use(cookieParser());
// „serwery statyczne”
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'bower_components/jquery/dist')));
if ('development' == env) {
app.use(logger('dev'));
app.use(errorHandler());
} else {
app.use(logger('short'));
}
// Routing
app = require('./config/apiRouter.js')(app, logControllerApi, tokenSecurityControllerApi, authControllerApi, notifyControllerApi);
app = require('./config/webRouter.js')(app, logController, authController, authControllerApi, tokenSecurityController, notifyController);
//sockety
io.sockets.on("connection", function (socket) {
socket.on("addLog", function (data) {
console.log("hehe");
io.sockets.emit("log", data);
});
socket.on("cpu", function (data) {
io.sockets.emit("cpu-monitor", data);
});
socket.on("memory", function (data) {
io.sockets.emit("memory-monitor", data);
});
socket.on("addAuditLog", function (data) {
io.sockets.emit("auditLog", data);
});
socket.on("analyze", function (data) {
io.sockets.emit("analyzeNotify", data);
});
socket.on("error", function (err) {
console.dir(err);
});
});
// uruchamiamy aplikację
httpServer.listen(port, function () {
console.log("Serwer nasłuchuje na porcie " + port);
});