-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
54 lines (48 loc) · 1.47 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
var app = require('http').createServer(handler);
var url = require('url');
var central = require('./endpoints');
var fs = require('fs');
app.listen(8614);
//function sendFile(req, res,
function handler (req, res)
{
var reqData = [];
req.on('data', function(chunk){ reqData.push(chunk); });
req.on('end', function()
{
var parsedUrl = url.parse(req.url);
// console.log(parsedUrl);
if (parsedUrl.path=='/')
{
res.writeHead(200);
central.init(function(initString)
{
res.end(initString);
});
} else {
var cmdArgs = parsedUrl.path.substring(1).split('/');
if (cmdArgs[0]=='pu')
{
central.pu(req, res, parsedUrl, reqData.join(''));
}
else if (cmdArgs[0]=='i')
{
console.log('===include===');
fs.readFile('application/include/'+cmdArgs[1] + '.js', function (err, data)
{
if (err) throw err;
res.end(data);
});
}
else if (cmdArgs[0]=='h')
{
console.log('===herm===');
fs.readFile('network/'+cmdArgs[1] + '.js', function (err, data)
{
if (err) throw err;
res.end(data);
});
}
}
});
}