-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverHttp.js
52 lines (44 loc) · 1.62 KB
/
serverHttp.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
// https://www.webrtc-experiment.com/
// Dependencies:
// 1. WebSocket
// 2. Node-Static
// Features:
// 1. WebSocket over Nodejs connection
// 2. Now rooms; it is a simple implementation!
module.exports = {
create: function() {
var fs = require('fs');
var _static = require('node-static');
var file = new _static.Server(__dirname);
this.settingsLoader = require('./settings.js');
var that = this;
// HTTP server
this.app = require('http').createServer(function (request, response) {
request.addListener('end', function () {
if (__wrongHTMLPage(request)) {
file.serveFile('/students.html', 301, {"Location": "/students.html"}, request, response);
} else {
file.serve(request, response);
}
}).resume();
});
function __wrongHTMLPage(request) {
// access to root
if (request.url === "/") {
return true;
// url is a html page...
} else if (~request.url.indexOf(".htm")) {
// ...but not a legit one
if (["/" + that.settingsLoader.getLecturerPage(), "/" + that.settingsLoader.getStudentsPage()].indexOf(request.url) == -1) {
return true;
}
}
return false;
}
return this.app;
},
run: function () {
this.app.listen(this.settingsLoader.getHttpServerPort());
console.log('Please open URL:', this.settingsLoader.createLecturerRunHttpAddress());
}
};