-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
73 lines (64 loc) · 1.79 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// © 2012 Sami Majadla and Rapcities Inc. All Rights Reserved
var cluster = require('cluster'),
numCPUs = require('os').cpus().length;
if(cluster.isMaster){
console.log(numCPUs + ' cores on this machine.');
for(var i = 0; i < numCPUs; i++)
cluster.fork();
cluster.on('exit', function(worker){
console.log('worker ' + worker.process.pid + ' died.');
cluster.fork();
});
process.on("SIGTERM", process.exit);
process.on("SIGINT", process.exit);
process.on("SIGKILL", process.exit);
/*process.on("SIGTERM", websiteDown);
process.on('exit',websiteDown);
process.on('SIGINT', websiteDown);*/
}
else{
connect = require('connect'),
url = require('url'),
locations = require('./locs');
function router(req, res, next) {
var arr = req.url.split('?')[0];
switch(arr){
case '/loc/getTypes': locations.getTypes(req,res); break;
case '/loc/getTypeIcon': locations.getTypeIcon(req,res); break;
case '/loc/browse': locations.browseLoc(req,res); break;
case '/loc/view': locations.view(req,res); break;
default:
next();
}
}
function checkWWW(req, res, next){
if(req.headers.host.match(/^www/)){
console.log('www');
res.writeHead(301, {'location':'http://'+req.headers.host.replace(/^www\./,'')+req.url});
res.end();
}
else
next();
}
function checkRobots(req, res, next){
var path = req.url.split('?')[0];
if(path == '/robots.txt'){
res.writeHead(404);
res.end();
} else{
res.writeHead(500);
res.end();
}
}
connect.createServer(
connect.favicon(__dirname+'/files/icons/favicon.ico'),
checkWWW,
connect.logger(),
connect.bodyParser(),
connect.query(),
require('./fileServer')(),
router,
//checkRobots).listen(80);
checkRobots).listen(8888);
console.log('Server has started.');
}