-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpserver.js
34 lines (22 loc) · 911 Bytes
/
httpserver.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
var HttpServer = function(nodeHttp, nodeFs, ipaddr, port) {
var httpServer = nodeHttp.createServer(function(req, res) {
if (req.url.search('.js') > -1) {
console.log(req.url)
res.writeHead(200, { 'Content-type': 'text/javascript'});
res.end(nodeFs.readFileSync(__dirname + '/client' + req.url));
} else if (req.url.search('index.html') > -1 || (req.url == '/')) {
res.writeHead(200, { 'Content-type': 'text/html'});
res.end(nodeFs.readFileSync(__dirname + '/client/index.html'));
} else {
res.writeHead(404, { 'Content-type': 'text/html'});
console.log("File not found: " + req.url);
}
});
httpServer.listen(port, ipaddr);
return httpServer;
};
if (typeof module !== 'undefined') {
module.exports = {
'HttpServer': HttpServer
};
}