This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
forked from sitcomlab/IVE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
122 lines (104 loc) · 3.59 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var colors = require('colors');
var express = require('express');
var bodyParser = require('body-parser');
var http = require('http');
var fs = require('fs');
var path = require('path');
var neo4j = require('neo4j-driver').v1;
// Create server
var app = express();
var environment = process.env.NODE_ENV || 'development';
var server_url = process.env.SERVER_URL || 'http://giv-sitcomdev.uni-muenster.de';
var httpPort = process.env.HTTP_PORT || 5000;
var httpsPort = process.env.HTTPS_PORT || (httpPort + 443);
var db_host = process.env.DB_HOST || '127.0.0.1';
var db_port = process.env.DB_PORT || '7687';
var db_user = process.env.DB_USER || 'neo4j';
var db_password = process.env.DB_PASSWORD || 'pw_4_neo4j';
var backend_user = process.env.BACKEND_USER || 'admin';
var backend_password = process.env.BACKEND_PASSWORD || 'admin';
var jwtSecret = process.env.JWTSECRET || 'superSecretKey';
exports.server_url = server_url;
exports.jwtSecret = jwtSecret;
exports.backend_account = {
username: backend_user,
password: backend_password
};
// Connect to Neo4j
var driver = neo4j.driver("bolt://" + db_host + ":" + db_port, neo4j.auth.basic(db_user, db_password));
exports.driver = driver;
var session = driver.session();
var query = "RETURN true;";
session
.run(query)
.then(function(result) {
session.close();
console.log(colors.blue(new Date() + " Neo4j is running on Port 7474"));
})
.catch(function(err) {
console.error(colors.red(new Date() + " Neo4j could not been accessed:\n" + JSON.stringify(err)));
});
// Load certificstes
if (environment === "production") {
var privateKey = fs.readFileSync('ssl/server.key', 'utf8');
var certificate = fs.readFileSync('ssl/server.crt', 'utf8');
var credentials = {
key: privateKey,
cert: certificate
};
}
// Setup settings
app.use(bodyParser.json({
limit: 52428800 // 50MB
}));
app.use(bodyParser.urlencoded({
extended: false,
limit: 52428800 // 50MB
}));
// Set folder for static files
app.use(express.static(__dirname + '/public', {
redirect: true
}));
// Load routes for API
var reset = require('./routes/reset');
var login = require('./routes/login');
var scenarios = require('./routes/scenarios');
var locations = require('./routes/locations');
var videos = require('./routes/videos');
var overlays = require('./routes/overlays');
var relationships = require('./routes/relationships');
var handlers = require('./routes/handlers');
app.use('/api', reset);
app.use('/api', login);
app.use('/api', scenarios);
app.use('/api', locations);
app.use('/api', videos);
app.use('/api', overlays);
app.use('/api', relationships);
app.use('/api', handlers);
// CMS Hook
var cms = require('./routes/cms');
app.use(cms);
// app.get('/cms', function (req, res) {
// path.resolve('public/cms/index.html')
// })
// Resolve path after refreshing inside app
app.get('/*', function(req, res, next) {
res.sendFile(path.resolve('public/index.html'));
});
// Start Webserver
var httpServer = http.createServer(app);
httpServer.listen(httpPort, function() {
console.log(colors.blue(new Date() + " HTTP-Server is listening at port " + httpPort));
});
if(environment === "production") {
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(httpsPort, function() {
console.log(colors.blue(new Date() + " HTTPS-Server is listening at port " + httpsPort));
});
}
// Start websocket server
var io = require('socket.io')(httpServer);
exports.io = io;
var sockets = require('./controllers/sockets.js').sockets;
console.log(colors.blue(new Date() + " Websocket-Server is listening"));