Skip to content

Commit

Permalink
configuration file for node
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Wnętrzak committed Jul 14, 2011
1 parent eb70406 commit 88671b0
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ db/*.rdb

config/redis.yml
config/database.yml
app-node/config.json
7 changes: 5 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ If you are using rvm, create new gemset to not mess with your default gems

cp config/redis.yml.example config/redis.yml
cp config/database.yml.example config/database.yml
cp app-node/config.json.example app-node/config.json

3. Setup Redis

Run redis (download from http://redis.io/download) - tested on 2.0 and 2.2 stable releases

4. Run node server (download from http://nodejs.org/#download) - tested on (v0.4.3, v0.4.7-v.0.4.9)
4. Run node server (download from http://nodejs.org/#download) - tested on (v0.4.3, v0.4.7-v.0.5.0)

node app-node/server.js
Go to app-node directory directly (this is necessary to load configuraion file using relative path see https://github.com/joyent/node/issues/1326)

cd app-node && node server.js

Tip: You can also use nvm https://github.com/creationix/nvm

Expand Down
1 change: 0 additions & 1 deletion app-node/config.json

This file was deleted.

6 changes: 6 additions & 0 deletions app-node/config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"username": "node",
"pasword": "secret",
"host": "localhost",
"port": 3000
}
50 changes: 24 additions & 26 deletions app-node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var initializeClientConnections = function() {
setTimeout(function() {
redisClient.hkeys(supervisionSessionsKey, function(err, resp) {
if (!_und.include(resp, userId)) {
PGS.request(PGS.supervision_members_path(supervisionId, userId), "DELETE");
PGS.request(PGS.node_supervision_member_path(supervisionId, userId), "DELETE");
}
});
}, 20000);
Expand All @@ -161,42 +161,43 @@ var initializeClientConnections = function() {
}

var PGS = {
//username: "node",

//password: "secret",
initialize: function() {
var config;
fs.readFile('./config.json', 'utf8', function (err, data) {
if (err) throw err;
config = JSON.parse(data);
PGS.username = config.username;
PGS.password = config.password;
PGS.host = config.host;
PGS.port = config.port;
});
},

auth_header: function() {
return "Basic " + new Buffer(PGS.username + ":" + PGS.password).toString("base64");
},

supervision_members_path: function(supervisionId, memberId) {
node_supervision_member_path: function(supervisionId, memberId) {
return "/node/supervisions/" + supervisionId + "/members/" + memberId;
},

request: function(path, method) {
//var body = JSON.stringify({ "supervision_membership": {"firstname": "Joe", "lastname": "Bloggs"} })
var options = {
host: 'localhost',
port: 3000,
path: path,
method: method,
headers: {"Content-Type": "application/json", "Accept": "application/json", "Authorization": PGS.auth_header()}//, "Content-Length": Buffer.byteLength(body)}
host: PGS.host,
port: PGS.port,
path: path,
method: method,
headers: {"Content-Type": "application/json", "Accept": "application/json", "Authorization": PGS.auth_header()}
};

var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
res.setEncoding('utf8');
});

req.on('error', function(e) {
console.log('problem with request: ' + e.message);
console.log('problem with request: ' + e.message);
});

// write data to request body
//req.write(body);
req.end();
}
}
Expand Down Expand Up @@ -247,10 +248,7 @@ var pingRedisClient = function(){
};
setInterval(pingRedisClient, 10000);

fs.readFile('/home/wojtek/Ruby/peergroup/app-node/config.json', 'utf8', function (err, data) {
if (err) throw err;
var config = JSON.parse(data);
PGS.username = config.username;
PGS.password = config.password;
console.log(JSON.parse(data));
});
/*
* Setup configuration to connect to rails application
*/
PGS.initialize();
3 changes: 1 addition & 2 deletions app/controllers/node/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
class Node::BaseController < ApplicationController
# protect_from_forgery :only => []
before_filter :authenticate_node

def authenticate_node
authenticate_or_request_with_http_basic do |username, password|
username == "node" && password == "secret"
username == NODE_CONFIG[:username] && password == NODE_CONFIG[:password]
end
end
end
1 change: 0 additions & 1 deletion app/controllers/node/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Node::MembersController < Node::BaseController
def destroy
@membership = supervision.memberships.find_by_user_id!(params[:id])
@membership.destroy
Rails.logger.info(@membership.inspect)
respond_with @membership
end

Expand Down
1 change: 1 addition & 0 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
task :link do
run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml"
run "ln -nfs #{shared_path}/config/redis.yml #{latest_release}/config/redis.yml"
run "ln -nfs #{shared_path}/app-node/config.json #{latest_release}/app-node/config.json"
end

namespace :apache do
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/node_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Create seperate config file when node will be moved from rails app repository
NODE_CONFIG = JSON.parse(File.read(Rails.root.join("app-node", "config.json"))).symbolize_keys

0 comments on commit 88671b0

Please sign in to comment.