This repository has been archived by the owner on Feb 17, 2018. It is now read-only.
forked from 4poc/feedability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
78 lines (66 loc) · 2.17 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
73
74
75
76
77
/**
* Feedability: Node.js Feed Proxy With Readability
* Copyright (c) 2011, Matthias -apoc- Hecker <http://apoc.cc/>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
console.log('Feedability : NodeJS Feed Proxy With Readability');
/**
* Core module for startup and shutdown of the feedability HTTP server.
*
* @fileOverview
*/
// built in libraries
//
var fs = require('fs'),
http = require('http'),
util = require('util');
// internal libraries
var cfg = require('./lib/cfg.js'),
log = new (require('./lib/log.js').Logger)('core'),
func = require('./lib/func.js'),
ProxyRequest = require('./lib/proxy.js').ProxyRequest;
// some variables used for the http server
var bind = cfg.get('proxy')['bind'];
var port = cfg.get('proxy')['port'];
var timeout;
function isdeadlock(){
if(server.connections>0)
{
log.error('timeout connections:'+server.connections);
process.exit(1);
}
else resetTimeout();
}
function resetTimeout(){
log.info('proxy alive:'+server.connections);
if(timeout) clearTimeout(timeout);
timeout=setTimeout(isdeadlock,60*1000);
}
// create the http server with the feed proxy
var server=http.createServer(function(request, response) {
resetTimeout()
try {
var proxy_request = new ProxyRequest(request, response);
proxy_request.process();
}
catch(exception) {
log.error('proxy request exception: '+exception);
}
});
server.maxConnections = 20;
server.listen(port, bind);
resetTimeout();
console.log('http server listening on '+bind+' port '+port);
console.log('open a browser and try: http://127.0.0.1:'+port+'/\n');