mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00
72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
// Generated by CoffeeScript 1.8.0
|
|
(function() {
|
|
var DEV, MONGODB_PORT, MONGODB_SERVER, app, mongo, server, url;
|
|
|
|
app = require('express')();
|
|
|
|
server = require('http').Server(app);
|
|
|
|
mongo = require('mongodb');
|
|
|
|
DEV = process.env.NODE_ENV === 'development';
|
|
|
|
MONGODB_SERVER = DEV ? 'localhost' : 'db_mongo';
|
|
|
|
MONGODB_PORT = parseInt(process.env.MONGODB_PORT || 27017, 10);
|
|
|
|
console.log(" ---> Starting NewsBlur Favicon server...");
|
|
|
|
if (!DEV && !process.env.NODE_ENV) {
|
|
console.log(" ---> Specify NODE_ENV=<development,production>");
|
|
return;
|
|
} else if (DEV) {
|
|
console.log(" ---> Running as development server");
|
|
} else {
|
|
console.log(" ---> Running as production server");
|
|
}
|
|
|
|
if (DEV) {
|
|
url = "mongodb://" + MONGODB_SERVER + ":" + MONGODB_PORT + "/newsblur";
|
|
} else {
|
|
url = "mongodb://" + MONGODB_SERVER + ":" + MONGODB_PORT + "/newsblur?replicaSet=nbset&readPreference=secondaryPreferred";
|
|
}
|
|
|
|
mongo.MongoClient.connect(url, (function(_this) {
|
|
return function(err, db) {
|
|
console.log(" ---> Connected to " + db + " / " + err);
|
|
return _this.collection = db.collection("feed_icons");
|
|
};
|
|
})(this));
|
|
|
|
app.get(/\/rss_feeds\/icon\/(\d+)\/?/, (function(_this) {
|
|
return function(req, res) {
|
|
var etag, feed_id;
|
|
feed_id = parseInt(req.params[0], 10);
|
|
etag = req.header('If-None-Match');
|
|
console.log(" ---> Feed: " + feed_id + " / " + etag);
|
|
return _this.collection.findOne({
|
|
_id: feed_id
|
|
}, function(err, docs) {
|
|
var body;
|
|
console.log("Req " + req.params[0] + ": " + feed_id + ", etag: " + etag + "/" + (docs != null ? docs.color : void 0) + " (err: " + err + ", docs? " + (!!(docs && docs.data)) + ")");
|
|
if (!err && etag && docs && (docs != null ? docs.color : void 0) === etag) {
|
|
return res.send(304);
|
|
} else if (!err && docs && docs.data) {
|
|
res.header('etag', docs.color);
|
|
body = new Buffer(docs.data, 'base64');
|
|
res.set("Content-Type", "image/png");
|
|
return res.status(200).send(body);
|
|
} else {
|
|
if (DEV) {
|
|
return res.redirect('/media/img/icons/circular/world.png');
|
|
} else {
|
|
return res.redirect('https://www.newsblur.com/media/img/icons/circular/world.png');
|
|
}
|
|
}
|
|
});
|
|
};
|
|
})(this));
|
|
|
|
app.listen(3030);
|
|
|
|
}).call(this);
|