2012-04-07 14:40:04 -07:00
|
|
|
express = require 'express'
|
|
|
|
mongo = require 'mongodb'
|
|
|
|
|
2012-12-24 21:18:40 -08:00
|
|
|
DEV = process.env.NODE_ENV == 'development'
|
2013-12-01 10:18:17 -05:00
|
|
|
MONGODB_SERVER = if DEV then 'localhost' else 'db_mongo'
|
2012-10-29 12:25:28 -07:00
|
|
|
MONGODB_PORT = parseInt(process.env.MONGODB_PORT or 27017, 10)
|
|
|
|
|
2012-12-24 21:18:40 -08:00
|
|
|
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'})
|
|
|
|
|
2012-12-24 21:05:22 -08:00
|
|
|
db = new mongo.Db('newsblur', server,
|
|
|
|
readPreference: mongo.ReadPreference.SECONDARY_PREFERRED
|
|
|
|
safe: false)
|
2012-04-07 14:40:04 -07:00
|
|
|
|
|
|
|
app = express.createServer()
|
|
|
|
app.use express.bodyParser()
|
2012-04-07 14:59:12 -07:00
|
|
|
|
|
|
|
db.open (err, client) =>
|
|
|
|
client.collection "feed_icons", (err, @collection) =>
|
2012-04-07 14:40:04 -07:00
|
|
|
|
|
|
|
app.get /^\/rss_feeds\/icon\/(\d+)\/?/, (req, res) =>
|
|
|
|
feed_id = parseInt(req.params, 10)
|
2012-04-07 15:33:41 -07:00
|
|
|
etag = req.header('If-None-Match')
|
2015-06-02 11:15:49 -07:00
|
|
|
@collection.findOne _id: feed_id, (err, docs) ->
|
2015-06-02 11:12:16 -07:00
|
|
|
console.log "Req: #{feed_id}, etag: #{etag}/#{docs?.color} (err: #{err}, docs? #{!!(docs and docs.data)})"
|
2014-03-28 13:49:03 -07:00
|
|
|
if not err and etag and docs and docs?.color == etag
|
2012-04-18 22:04:13 -07:00
|
|
|
res.send 304
|
|
|
|
else if not err and docs and docs.data
|
|
|
|
res.header 'etag', docs.color
|
|
|
|
res.send new Buffer(docs.data, 'base64'),
|
|
|
|
"Content-Type": "image/png"
|
2012-04-07 14:59:12 -07:00
|
|
|
else
|
2014-08-10 12:56:09 -07:00
|
|
|
if DEV
|
|
|
|
res.redirect '/media/img/icons/circular/world.png'
|
|
|
|
else
|
|
|
|
res.redirect 'https://www.newsblur.com/media/img/icons/circular/world.png'
|
2012-04-07 15:33:41 -07:00
|
|
|
|
2012-04-07 14:40:04 -07:00
|
|
|
app.listen 3030
|