Skip to content

Commit

Permalink
Merge pull request #2 from robbinhan/goodrain
Browse files Browse the repository at this point in the history
Goodrain
  • Loading branch information
robbinhan committed Oct 27, 2015
2 parents 6cc60da + 0577706 commit cefd673
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 32 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node main.js
4 changes: 2 additions & 2 deletions assets/js/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function fetchFeed(url) {

dispatch(showGistsRequest(url));

axios.get('http://localhost:9222/feed?url=' + url).then((rep) => {
axios.get('http://localhost:5000/feed?url=' + url).then((rep) => {
console.log(rep.data);
let feeds = rep.data.responseData.feed.entries;
console.log(feeds)
Expand Down Expand Up @@ -138,7 +138,7 @@ export function fetchFeed(url) {

export function subFeeds(url) {
return function (dispatch) {
axios.get('http://localhost:9222/feed?url=' + url).then((rep) => {
axios.get('http://localhost:5000/feed?url=' + url).then((rep) => {
console.log(rep.data);
let feed = rep.data.responseData.feed;
var feedObject = {title: feed.title, feedUrl: feed.feedUrl, link: feed.link, author: feed.author}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const store = configureStore;
let node = document.getElementById('app');
ReactDOM.render(
<App store={store} />,
node);
node);
102 changes: 82 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
var request = require('request');
var http = require('http');
var url = require('url');
var fs = require("fs");
var path = require('path');


var mime = {
"css": "text/css",
"gif": "image/gif",
"html": "text/html",
"ico": "image/x-icon",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"js": "text/javascript",
"json": "application/json",
"pdf": "application/pdf",
"png": "image/png",
"svg": "image/svg+xml",
"swf": "application/x-shockwave-flash",
"tiff": "image/tiff",
"txt": "text/plain",
"wav": "audio/x-wav",
"wma": "audio/x-ms-wma",
"wmv": "video/x-ms-wmv",
"xml": "text/xml"
};

http.createServer(function(req, res) {
var srvUrl = url.parse(req.url, true);
if (srvUrl.pathname != '/feed') {
var realPath = srvUrl.pathname == '/' ? 'index.html' : './' + srvUrl.pathname;

fs.exists(realPath, function(exists) {
if (!exists) {
res.writeHead(404, {
'Content-Type': 'text/plain'
});

res.write("This request URL " + srvUrl.pathname + " was not found on this server.");
res.end();
} else {
console.log(realPath);
fs.readFile(realPath, "binary", function(err, file) {
if (err) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end(err);
} else {
var ext = path.extname(realPath);
ext = ext ? ext.slice(1) : 'unknown';
var contentType = mime[ext] || "text/plain";
res.writeHead(200, {
'Content-Type': contentType
});
res.write(file, "binary");
res.end();
}
});
}
});
}

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

Expand All @@ -13,33 +71,37 @@ http.createServer(function (req, res) {
var randomNum = new Date().getTime() + Math.floor((Math.random() * 10000) + 1);
q = encodeURIComponent(q);

parseFeed(q, num, function(err,feeds){
parseFeed(q, num, function(err, feeds) {
jsonFeeds = JSON.parse(feeds)
if (jsonFeeds.responseStatus != 200) {
parseFeed(q, num, function(err,feeds){
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(feeds);
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.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end(feeds);
}
})
}).listen(9222);
}).listen(5000);

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;
request({
headers: {
'Cache-Control': 'max-age=0'
},
timeout: 60000,
url: apiUrl,
strictSSL: true,
}, function(err, res) {
callback(err,res.body);
});
function parseFeed(q, num, callback) {
apiUrl = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=' + num + '&q=' + q;
request({
headers: {
'Cache-Control': 'max-age=0'
},
timeout: 60000,
url: apiUrl,
strictSSL: true,
}, function(err, res) {
callback(err, res.body);
});
}
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "ReactRss",
"version": "0.1.0",
"private": true,
"engines": {
"node": "4.1.0"
},
"devDependencies": {
"autoprefixer": "^6.0.3",
"babelify": "^6.3.0",
Expand All @@ -12,12 +15,11 @@
"gulp": "^3.8.8",
"gulp-postcss": "^6.0.0",
"redux-devtools": "^2.1.5",
"vinyl-source-stream": "^1.1.0"
},
"dependencies": {
"axios": "^0.6.0",
"vinyl-source-stream": "^1.1.0",
"cssnext": "^1.8.4",
"feedparser": "^1.1.3",
"socks5-https-client": "^1.1.1",
"axios": "^0.6.0",
"localforage": "^1.2.10",
"lodash": "^3.10.1",
"react": "^0.14.0",
Expand All @@ -26,8 +28,9 @@
"redux": "^3.0.2",
"redux-actions": "^0.8.0",
"redux-diff-logger": "0.0.6",
"redux-thunk": "^1.0.0",
"request": "^2.64.0",
"socks5-https-client": "^1.1.1"
"redux-thunk": "^1.0.0"
},
"dependencies": {
"request": "^2.64.0"
}
}
4 changes: 2 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function fetchFeed(url) {

dispatch(showGistsRequest(url));

_axios2['default'].get('http://localhost:9222/feed?url=' + url).then(function (rep) {
_axios2['default'].get('http://localhost:5000/feed?url=' + url).then(function (rep) {
console.log(rep.data);
var feeds = rep.data.responseData.feed.entries;
console.log(feeds);
Expand Down Expand Up @@ -164,7 +164,7 @@ function fetchFeed(url) {

function subFeeds(url) {
return function (dispatch) {
_axios2['default'].get('http://localhost:9222/feed?url=' + url).then(function (rep) {
_axios2['default'].get('http://localhost:5000/feed?url=' + url).then(function (rep) {
console.log(rep.data);
var feed = rep.data.responseData.feed;
var feedObject = { title: feed.title, feedUrl: feed.feedUrl, link: feed.link, author: feed.author };
Expand Down

0 comments on commit cefd673

Please sign in to comment.