Skip to content

Commit

Permalink
Pass in configuration rather than reading it from a default file, add…
Browse files Browse the repository at this point in the history
… support for registering types
  • Loading branch information
mixu committed Oct 4, 2012
1 parent a60d889 commit d053031
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
1 change: 0 additions & 1 deletion api/test/radar.test.js
Expand Up @@ -17,7 +17,6 @@ var fs = require('fs'),
var subdomain = 'support',
frontend,
backend,
config = require(__dirname + '/../../configuration.js'),
routes;

var Client = new ClientScope({
Expand Down
6 changes: 0 additions & 6 deletions configuration.js

This file was deleted.

10 changes: 9 additions & 1 deletion core/lib/persistence.js
@@ -1,6 +1,10 @@
var redisLib = require('redis'),
logging = require('minilog')('persistence'),
configuration = require('../../configuration');
// defaults
configuration = {
redis_host: 'localhost',
redis_port: 6379,
};

var client, isConnecting = false;

Expand All @@ -22,6 +26,10 @@ function redis() {

function Persistence() { };

Persistence.setConfig = function(config) {
configuration = config;
};

Persistence.applyPolicy = function(multi, key, policy) {
if(policy.maxCount) {
multi.zremrangebyrank(key, 0, -policy.maxCount-1, function(err, res) {
Expand Down
7 changes: 4 additions & 3 deletions core/lib/type.js
@@ -1,4 +1,3 @@

var Types = {};

function get(type) {
Expand Down Expand Up @@ -37,7 +36,9 @@ function getByExpression(name) {

module.exports = {
get: get,
getByExpression: getByExpression
getByExpression: getByExpression,
register: function(name, type) {
Types[name] = type;
}
};


5 changes: 5 additions & 0 deletions readme.md
Expand Up @@ -7,3 +7,8 @@ Installing from scratch:
- git clone git@github.com:zendesk/radar.git
- npm install
- npm start

## Copyright and License

Copyright 2012, Zendesk Inc.
Licensed under the Apache License Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
8 changes: 6 additions & 2 deletions server.js
@@ -1,6 +1,10 @@
var http = require('http'),

configuration = require('./configuration.js'),
configuration = {
redis_host: 'localhost',
redis_port: 6379,
port: 8000
},
Radar = require('./server/server.js'),
Api = require('./api/api.js'),
Minilog = require('minilog');
Expand Down Expand Up @@ -30,6 +34,6 @@ server = http.createServer(p404);
Api.attach(server);

// Radar server
Radar.attach(server, require('engine.io'));
Radar.attach(server, configuration);

server.listen(configuration.port);
6 changes: 3 additions & 3 deletions server/server.js
Expand Up @@ -8,8 +8,7 @@ var redis = require('redis'),
PresenceMaintainer = require('../core').PresenceMaintainer,
Heartbeat = require('heartbeat'),
logging = require('minilog')('server'),
hostname = require('os').hostname(),
configuration = require('../configuration');
hostname = require('os').hostname();

// Parse JSON
function parseJSON(data) {
Expand All @@ -33,9 +32,10 @@ function Server() {
MiniEventEmitter.mixin(Server);

// Attach to a http server
Server.prototype.attach = function(server) {
Server.prototype.attach = function(server, configuration) {
var self = this,
engine = require('engine.io');
require('../core').Persistence.setConfig(configuration);
this.subscriber = redis.createClient(configuration.redis_port, configuration.redis_host);
this.subscriber.on('message', function(name, data) {
logging.debug('#redis_in', name, data);
Expand Down

0 comments on commit d053031

Please sign in to comment.