forked from ksimuk/ts-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
43 lines (34 loc) · 906 Bytes
/
start.js
File metadata and controls
43 lines (34 loc) · 906 Bytes
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
'use strict';
var http = require('http');
var config = require('./config');
var stream = require('./lib/stream');
var playlist = require('./lib/playlist');
var iniparser = require('iniparser');
var cfgPath = process.argv[3] || './config.ini';
function start() {
playlist.start();
http.createServer(function (req, res) {
var pathname = req.url;
if (pathname === '/playlist') {
req.setEncoding('utf8');
playlist.request(res);
return;
}
var parts = pathname.split('/');
console.log(parts);
if (parts.length > 1 && parts[1] === 'stream') {
stream.attach(req, res, parts[2]);
return;
}
// not found handle
res.writeHead(404, {
'Content-Type': 'text/plain'
});
res.end('NotFound\n');
}).listen(config.port, '0.0.0.0');
console.log('Server running at ' + config.local_domain);
}
iniparser.parse(cfgPath, function (err, data) {
config.set(data);
start();
});