This repository has been archived by the owner on Apr 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
server.js
51 lines (42 loc) · 1.52 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
// Muaz Khan - www.MuazKhan.com
// MIT License - www.WebRTC-Experiment.com/licence
// Source Code - https://github.com/muaz-khan/WebRTC-Scalable-Broadcast
var fs = require("fs");
var path = require('path');
var app = require('http').createServer(function (request, response) {
var uri = require('url').parse(request.url).pathname,
filename = path.join(process.cwd(), uri);
var isWin = !!process.platform.match(/^win/);
if (fs.statSync(filename).isDirectory()) {
if(!isWin) filename += '/index.html';
else filename += '\\index.html';
}
fs.exists(filename, function (exists) {
if (!exists) {
response.writeHead(404, {
"Content-Type": "text/plain"
});
response.write('404 Not Found: ' + filename + '\n');
response.end();
return;
}
fs.readFile(filename, 'binary', function (err, file) {
if (err) {
response.writeHead(500, {
"Content-Type": "text/plain"
});
response.write(err + "\n");
response.end();
return;
}
response.writeHead(200);
response.write(file, 'binary');
response.end();
});
});
});
app = app.listen(process.env.PORT || 8888, process.env.IP || "0.0.0.0", function() {
var addr = app.address();
console.log("Server listening at", addr.address + ":" + addr.port);
});
require('./WebRTC-Scalable-Broadcast.js')(app);