NewsBlur-viq/node/favicons.js
Samuel Clay a67df54101 Merge branch 'master' into circular
* master:
  Adding task servers to db firewall.
  Adding redis cache. Returning favicon server.
  Better munin plugins for redis and mongo.
  Removing unused redis keys for shared/comments. Dry-run.
  Adding read preference to migration.
  Migration to create story_hash for missing feeds.
  Making a clearer description of slow feeds.
  Upping feed fetches, slowing down fetch interval for less active feeds, setting premium expire time to one year from most recent payment date (as opposed to borked payment gap logic), and adding logginf or tasking feeds.
  Switching check for HAProxy'ied socket.io to dev instead of www. Thanks @anaconda!
  Sync delay in mongodb and updating story hash migration.
  Upping feed fetches.
  Fix force close when attempting to fetch a user with a null user.id value
  Fix force close updating ProfileActivityFragment if no profile response was received
  Move creating ImageLoader in NewsBlurApplication to onCreate to ensure that base context has been set and prevent force close
  Boosting fetches.
  Fix duplicate requirement

Conflicts:
	fabfile.py
2013-03-28 19:09:14 -07:00

68 lines
1.7 KiB
JavaScript

// Generated by CoffeeScript 1.4.0
(function() {
var DEV, MONGODB_PORT, MONGODB_SERVER, app, db, express, mongo, server,
_this = this;
express = require('express');
mongo = require('mongodb');
DEV = process.env.NODE_ENV === 'development';
MONGODB_SERVER = DEV ? 'localhost' : 'db24';
MONGODB_PORT = parseInt(process.env.MONGODB_PORT || 27017, 10);
if (DEV) {
server = new mongo.Server(MONGODB_SERVER, MONGODB_PORT, {
auto_reconnect: true,
poolSize: 12
});
} else {
server = new mongo.ReplSetServers([
new mongo.Server(MONGODB_SERVER, MONGODB_PORT, {
auto_reconnect: true
})
], {
rs_name: 'nbset'
});
}
db = new mongo.Db('newsblur', server, {
readPreference: mongo.ReadPreference.SECONDARY_PREFERRED,
safe: false
});
app = express.createServer();
app.use(express.bodyParser());
db.open(function(err, client) {
return client.collection("feed_icons", function(err, collection) {
_this.collection = collection;
});
});
app.get(/^\/rss_feeds\/icon\/(\d+)\/?/, function(req, res) {
var etag, feed_id;
feed_id = parseInt(req.params, 10);
etag = req.header('If-None-Match');
return _this.collection.findOne({
_id: feed_id
}, function(err, docs) {
if (!err && etag && docs && docs.color === etag) {
return res.send(304);
} else if (!err && docs && docs.data) {
res.header('etag', docs.color);
return res.send(new Buffer(docs.data, 'base64'), {
"Content-Type": "image/png"
});
} else {
return res.redirect('/media/img/icons/circular/world.png');
}
});
});
app.listen(3030);
}).call(this);