mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00

* master: (22 commits) Whoops Better logging for broken paypal ipns. Adding RSS Tracker for Windows to Goodies. Refactoring socketio so real-time works around username restrictions. Socket.IO v3 on the server too. Switching to Socket.IO v3. Haproxy splitting for socketio 3 Socket.io 3 Handling missing feed. Only nb.local.com uses ports for websockets. Adding GrazeTEN Full node install on setup. Updating toprc Changing mongodb server. Fixing toprc Attempting to collect queries for 1% of requests by using DEBUG. Fixing mongo install. Recalculating premium expiration to take into account forced expirations after gifts. Fixing never expire -> 1 year Adding 1 year expire to admin. ...
128 lines
4.4 KiB
JavaScript
128 lines
4.4 KiB
JavaScript
// Generated by CoffeeScript 2.5.1
|
|
(function() {
|
|
var DEV, DOCKER, REDIS_SERVER, SECURE, app, certificate, fs, io, log, options, privateKey, redis;
|
|
|
|
fs = require('fs');
|
|
|
|
redis = require('redis');
|
|
|
|
log = require('./log.js');
|
|
|
|
DEV = process.env.NODE_ENV === 'development';
|
|
|
|
DOCKER = process.env.NODE_ENV === 'docker';
|
|
|
|
REDIS_SERVER = process.env.NODE_ENV === 'development' ? 'localhost' : DOCKER ? 'redis' : 'db_redis_pubsub';
|
|
|
|
SECURE = !!process.env.NODE_SSL;
|
|
|
|
REDIS_PORT = DOCKER ? 6579 : 6379;
|
|
|
|
log.debug("Starting NewsBlur unread count server...");
|
|
|
|
if (!DEV && !process.env.NODE_ENV) {
|
|
log.debug("Specify NODE_ENV=<development,production>");
|
|
return;
|
|
} else if (DEV) {
|
|
log.debug("Running as development server");
|
|
} else {
|
|
log.debug("Running as production server");
|
|
}
|
|
|
|
if (SECURE) {
|
|
privateKey = fs.readFileSync('/srv/newsblur/config/certificates/newsblur.com.key').toString();
|
|
certificate = fs.readFileSync('/srv/newsblur/config/certificates/newsblur.com.crt').toString();
|
|
// ca = fs.readFileSync('./config/certificates/intermediate.crt').toString()
|
|
options = {
|
|
port: 8889,
|
|
key: privateKey,
|
|
cert: certificate
|
|
};
|
|
app = require('https').createServer(options);
|
|
io = require('socket.io')(app, {
|
|
path: "/v3/socket.io"
|
|
});
|
|
app.listen(options.port);
|
|
log.debug(`Listening securely on port ${options.port}`);
|
|
} else {
|
|
options = {
|
|
port: 8888
|
|
};
|
|
app = require('http').createServer();
|
|
io = require('socket.io')(app, {
|
|
path: "/v3/socket.io"
|
|
});
|
|
app.listen(options.port);
|
|
log.debug(`Listening on port ${options.port}`);
|
|
}
|
|
|
|
// io.set('transports', ['websocket'])
|
|
|
|
// io.set 'store', new RedisStore
|
|
// redisPub : rpub
|
|
// redisSub : rsub
|
|
// redisClient : rclient
|
|
io.on('connection', function(socket) {
|
|
var ip;
|
|
ip = socket.handshake.headers['X-Forwarded-For'] || socket.handshake.address;
|
|
socket.on('subscribe:feeds', (feeds, username) => {
|
|
var ref;
|
|
this.feeds = feeds;
|
|
this.username = username;
|
|
log.info(this.username, `Connecting (${this.feeds.length} feeds, ${ip}),` + ` (${io.engine.clientsCount} connected) ` + ` ${SECURE ? "(SSL)" : "(non-SSL)"}`);
|
|
if (!this.username) {
|
|
return;
|
|
}
|
|
socket.on("error", function(err) {
|
|
return log.debug(`Error (socket): ${err}`);
|
|
});
|
|
if ((ref = socket.subscribe) != null) {
|
|
ref.quit();
|
|
}
|
|
socket.subscribe = redis.createClient(REDIS_PORT, REDIS_SERVER);
|
|
socket.subscribe.on("error", (function(_this) {
|
|
return function(err) {
|
|
var _ref1;
|
|
log.info(_this.username, "Error: " + err + " (" + _this.feeds.length + " feeds)");
|
|
return (_ref1 = socket.subscribe) != null ? _ref1.quit() : void 0;
|
|
};
|
|
})(this));
|
|
socket.subscribe.on("connect", (function(_this) {
|
|
return function() {
|
|
var feeds_story;
|
|
log.info(_this.username, ("Connected (" + _this.feeds.length + " feeds, " + ip + "),") + (" (" + io.engine.clientsCount + " connected) ") + (" " + (SECURE ? "(SSL)" : "(non-SSL)")));
|
|
socket.subscribe.subscribe(_this.feeds);
|
|
feeds_story = _this.feeds.map(function(f) {
|
|
return "" + f + ":story";
|
|
});
|
|
socket.subscribe.subscribe(feeds_story);
|
|
return socket.subscribe.subscribe(_this.username);
|
|
};
|
|
})(this));
|
|
return socket.subscribe.on('message', (function(_this) {
|
|
return function(channel, message) {
|
|
log.info(_this.username, "Update on " + channel + ": " + message);
|
|
if (channel === _this.username) {
|
|
return socket.emit('user:update', channel, message);
|
|
} else if (channel.indexOf(':story') >= 0) {
|
|
return socket.emit('feed:story:new', channel, message);
|
|
} else {
|
|
return socket.emit('feed:update', channel, message);
|
|
}
|
|
};
|
|
})(this));
|
|
});
|
|
return socket.on('disconnect', () => {
|
|
var ref, ref1;
|
|
if ((ref = socket.subscribe) != null) {
|
|
ref.quit();
|
|
}
|
|
return log.info(this.username, `Disconnect (${(ref1 = this.feeds) != null ? ref1.length : void 0} feeds, ${ip}),` + ` there are now ${io.engine.clientsCount} users. ` + ` ${SECURE ? "(SSL)" : "(non-SSL)"}`);
|
|
});
|
|
});
|
|
|
|
io.sockets.on('error', function(err) {
|
|
return log.debug(`Error (sockets): ${err}`);
|
|
});
|
|
|
|
}).call(this);
|