-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.js
executable file
·77 lines (65 loc) · 2.49 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
var port = process.env.PORT || 3000,
http = require('http'),
url = require("url"),
path = require("path"),
fs = require('fs'),
mime = require('mime-types');
// node server.js
const exec = require('child_process').exec;
exec('node ' + __dirname + '/jspm_packages/github/muaz-khan/RTCMultiConnection*/server.js bad_file | wc -l', {env: {number: 1234}}, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
console.log('socket.io is listening at: http://127.0.0.1:9001/');
var log = function(entry) {
fs.appendFileSync('/tmp/webrtc.log', new Date().toISOString() + ' - ' + entry + '\n');
};
var server = http.createServer(function (req, res) {
if (req.method === 'POST') {
var body = '';
req.on('data', function(chunk) {
body += chunk;
});
req.on('end', function() {
if (req.url === '/') {
log('Received message: ' + body);
} else if (req.url = '/scheduled') {
log('Received task ' + req.headers['x-aws-sqsd-taskname'] + ' scheduled at ' + req.headers['x-aws-sqsd-scheduled-at']);
}
res.writeHead(200, 'OK', {'Content-Type': 'text/plain'});
res.end();
});
} else {
req.url = req.url.indexOf('.') === -1 ? req.url + 'index.html' : req.url;
var uri = url.parse(req.url).pathname, filename = path.join(process.cwd(), uri);
fs.exists(filename, function(exists) {
if(!exists) {
res.writeHead(404, {"Content-Type": "text/plain"});
res.write("404 Not Found\n");
res.end();
return;
}
if (fs.statSync(filename).isDirectory()) filename += '/index.html';
fs.readFile(filename, "binary", function(err, file) {
if(err) {
res.writeHead(500, {"Content-Type": "text/plain"});
res.write(err + "\n");
res.end();
return;
}
res.setHeader("Content-Type", mime.lookup(req.url));
res.writeHead(200);
res.write(file, "binary");
res.end();
});
});
}
});
// Listen on port 3000, IP defaults to 127.0.0.1
server.listen(port);
// Put a friendly message on the terminal
console.log('Server running at http://127.0.0.1:' + port + '/');