-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
74 lines (67 loc) · 2.44 KB
/
server.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
/*TODO:
*Create Admin Panel Interface
* More validation on database values (password 8chars etc..) move date formating to schema
* Messages StartDate and EndDate should contain date and time (currently only date)
=> Update : momentjs imported
* Limit messages before a date.
* Get Users search criteria for admins (string, requesting admin, requesting member)
* Password Hashing (sha256 client, bcrypt server)
* force https (local ssl cert & key)
* Log : schema of all events happening in the system
[
User signed in,
User signed out,
User created,
User modified,
User requested becoming member,
User reported an accident,
Admin signed in,
Admin signed out,
Admin posted message,
Admin Approuved new member,
Admin Removed member,
Admin blocked user,
Admin added admin,
Admin removed admin,
]
*/
var http = require('http');
var path = require('path');
var bodyParser = require('body-parser');
var express = require('express');
var webservice = require("./api/v1/webservice");
var socketHandler = require("./socket");
var database = require('./database/DatabaseHandler');
var utils = require('./utils');
var app = express();
var server = http.createServer(app);
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(function(error, req, res, next) {
//Body parser error handling
console.log(error);
res.status(error.statusCode || 500).send({
success: false,
error: 'Parsing Error'
});
});
/*Opening database. the rest of the app depends on it.
In case of an error, nothing else is loaded.*/
database.init(function() {
//Remove images that are not linked to documents in the database to clear storage
utils.CleanUnusedImages();
/*This is where the web service is initialized and linked to our server
*Requires tha express app instance to manage the routes*/
webservice.Attach(app);
//Attaching the socket.io server
socketHandler.Attach(server);
//This will serve the front end in the client folder
app.use(express.static(path.resolve(__dirname, 'client')));
//Start Server.
server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", function() {
var addr = server.address();
console.log("server listening at", addr.address + ":" + addr.port + ' (' + utils.dateFormat(Date.now(),"DD/MM/YYYY HH:mm:ss") + ')');
});
});