Skip to content

Commit

Permalink
Merge pull request #1 from robbinhan/goodrain
Browse files Browse the repository at this point in the history
不设置代理的版本
  • Loading branch information
robbinhan committed Oct 24, 2015
2 parents d7f5de5 + baf5da4 commit 6cc60da
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
var Agent = require('socks5-https-client/lib/Agent');
var request = require('request');
var http = require('http');
var url = require('url');
var socksHost = '127.0.0.1';
var socksPort = 7070;

http.createServer(function (req, res) {
var srvUrl = url.parse(req.url,true);
var q = srvUrl.query.url
var num = srvUrl.query.num || 10;
var srvUrl = url.parse(req.url,true);
var q = srvUrl.query.url
var num = srvUrl.query.num || 10;

/* Use the randomNum and the time to invalidate the Google cache and
fetch the latest articles.
*/
var randomNum = new Date().getTime() + Math.floor((Math.random() * 10000) + 1);
q = encodeURIComponent(q );
/* Use the randomNum and the time to invalidate the Google cache and
fetch the latest articles.
*/
var randomNum = new Date().getTime() + Math.floor((Math.random() * 10000) + 1);
q = encodeURIComponent(q);

parseFeed(q, num, function(err,feeds){
jsonFeeds = JSON.parse(feeds)
if (jsonFeeds.responseStatus != 200) {
parseFeed(q, num, function(err,feeds){
jsonFeeds = JSON.parse(feeds)
console.log('staus',jsonFeeds.responseStatus)
if (jsonFeeds.responseStatus != 200) {
parseFeed(q, num, function(err,feeds){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(feeds);
})
} else {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(feeds);
}
})
} else {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(feeds);
}
})
}).listen(9222);

console.log('Server running on port 9222.');


function parseFeed (q,num,callback) {
apiUrl = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num='+ num+ '&q='+q;
console.log(apiUrl);
request({
headers: {
'Cache-Control': 'max-age=0'
},
timeout: 60000,
url: apiUrl,
strictSSL: true,
agentClass: Agent,
agentOptions: {
socksHost: socksHost,
socksPort: socksPort
}
}, function(err, res) {
// console.log(err,res.body);
callback(err,res.body);
callback(err,res.body);
});
}

0 comments on commit 6cc60da

Please sign in to comment.