aboutsummaryrefslogtreecommitdiffstats
path: root/app.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2014-08-30 12:13:43 -0700
committerAdam Soltys <[email protected]>2014-08-30 12:13:43 -0700
commit8fe5b97004189845ee98a02ab197ca080ff0a002 (patch)
tree1b56bad23c70ddbcf3eb965a1051eb5c03147eb5 /app.js
parenteb4c625949f7b20cbbd59dde3fd2af1d53f4449e (diff)
downloadcoinos-server-8fe5b97004189845ee98a02ab197ca080ff0a002.tar.gz
coinos-server-8fe5b97004189845ee98a02ab197ca080ff0a002.zip
Reimplement fetch rates function
Diffstat (limited to 'app.js')
-rw-r--r--app.js28
1 files changed, 12 insertions, 16 deletions
diff --git a/app.js b/app.js
index b568e65a..9e5c3fed 100644
--- a/app.js
+++ b/app.js
@@ -88,24 +88,20 @@
return next();
};
- fetchRates = function() {
- var file;
- file = 'public/js/rates.json';
- fs.truncate(file, 0, function() {
- var r, stream;
- stream = fs.createWriteStream(file);
- r = request("https://api.bitcoinaverage.com/exchanges/all");
- r.on('data', function(chunk) {
- return stream.write(chunk);
- });
- return r.on('error', function(error) {
- return console.log(error);
- });
+ (fetchRates = function() {
+ request("https://api.bitcoinaverage.com/exchanges/all", function(error, response, body) {
+ var file, stream;
+ try {
+ require('util').isDate(JSON.parse(body).timestamp);
+ file = 'public/js/rates.json';
+ stream = fs.createWriteStream(file);
+ return fs.truncate(file, 0, function() {
+ return stream.write(body);
+ });
+ } catch (_error) {}
});
return setTimeout(fetchRates, 120000);
- };
-
- fetchRates();
+ })();
app.get('/', cache, sessions["new"]);