Skip to content

Commit

Permalink
- bluemix fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed Jan 26, 2016
1 parent 00c5030 commit 0e37b8b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 76 deletions.
25 changes: 5 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,17 @@ app.use(function(err, req, res, next) { // = development error handler, print s
});

////////////// Launch //////////////
var server = app.listen(port, host); //gogo application
var server = http.createServer(app).listen(port, function() {});
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
server.timeout = 240000; // Ta-da.
console.log('info', '------------------------------------------ Server Up - ' + host + ':' + port + ' ------------------------------------------');
if(process.env.PRODUCTION) console.log('Running using Production settings');
else console.log('Running using Developer settings');


var WebSocketServer = require('ws').Server, wss = new WebSocketServer({ port: 3001 });

var ws = require('ws');
var wss = new ws.Server({server: server});

wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received ws msg:', message);
Expand All @@ -127,7 +128,6 @@ wss.on('connection', function connection(ws) {
function get_marbles(){
console.log('fetching all marble data');
contract.cc.read('marbleIndex', cb_got_index);
//ws.send(JSON.stringify({msg: 'hey there client'}));
}


Expand Down Expand Up @@ -183,7 +183,7 @@ wss.on('connection', function connection(ws) {
var Obc1 = require('./utils/obc-js/index');
var obc = new Obc1();
var contract = {};
var peers = [
var peers = [
{
"discovery_host": "169.53.72.250",
"discovery_port": "33435",
Expand Down Expand Up @@ -267,19 +267,4 @@ obc.load(options, cb_ready); //parse/load chaincode
function cb_ready(err, cc){
obc.save('./');
contract = cc;
//obc.clear();
//contract.cc.read('a', cb_next);
//contract.cc.deploy('init', ["a", "101", "b", "202"], cb_next);
//contract.cc.read('a', cb_next);
/*
function cb_next(e, value){
contract.cc.read('a', cb_next2);
contract.cc.write('a', (value + 1), cb_next2);
contract.invoke(["a", "b", "5"], cb_next2);
}
function cb_next2(){
contract.cc.read('a');
contract.cc.read('b');
}
*/
}
6 changes: 3 additions & 3 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
applications:
- disk_quota: 1024M
host: obc
name: obc
host: marbles
name: marbles
command: "node app.js"
path: "."
domain: stage1.mybluemix.net
instances: 1
memory: 1024M
memory: 512M
services:
- myblockchain
7 changes: 5 additions & 2 deletions public/js/simplestuff1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global bag */
/* global $ */
var ws = {};

Expand Down Expand Up @@ -100,8 +101,10 @@ function connect_to_server(){

connect();
function connect(){
var wsUri = "ws://localhost:3001";
//var wsUri = "wss://broker.obchain.com/network/" + name;
//var wsUri = "ws://localhost:3000";
//var wsUri = "ws://marbles.stage1.mybluemix.net";
var wsUri = "ws://" + bag.setup.SERVER.EXTURI;

ws = new WebSocket(wsUri);
ws.onopen = function(evt) { onOpen(evt); };
ws.onclose = function(evt) { onClose(evt); };
Expand Down
48 changes: 3 additions & 45 deletions routes/site_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,17 @@
var express = require('express');
var router = express.Router();
var fs = require("fs");
var setup = require('../setup.js');

// Load our modules.
var aux = require("./site_aux.js");
var rest = require("../utils/rest.js");

/*
var Obc1 = require('../utils/obc-js/index');
var obc = new Obc1();
var contract = {};
var options = {
zip_url: 'https://codeload.github.com/dshuffma-ibm/simplestuff/zip/master',
dir: 'simplestuff-master',
git_url: 'https://github.com/dshuffma-ibm/simplestuff',
name: 'ba0c1e910af1b479c606e5295050499f3d558ebb78a49a489af437f17ea59025c56e990a1652893437f578a9aca449974e70d54e0fd2d1b942f46b4a81a55425'
};
//obc.load(options, cb_ready2); //parse/load chaincode
function cb_ready2(err, cc){
contract = cc;
obc.save('./');
};
*/

// ============================================================================================================================
// Home
// ============================================================================================================================
router.route("/").get(function(req, res){
res.render('home', {title: 'Home', bag: {}} );
res.render('home', {title: 'Home', bag: {setup: setup}} );
});


Expand All @@ -52,33 +36,7 @@ router.route("/cci").get(function(req, res){
catch(e){
console.log('error loading cc.json', e);
};
res.render('investigate', {title: 'Investigator', bag: {cc: cc}} );
res.render('investigate', {title: 'Investigator', bag: {cc: cc, setup: setup}} );
});


// ============================================================================================================================
// Create
// ============================================================================================================================
/*router.route("/create").post(function(req, res){
//console.log('!', req.body);
var errors = [];
if(!req.body || !req.body.name) errors.push('name is requied');
if(!req.body || !req.body.color) errors.push('color is requied');
if(!req.body || !req.body.size) errors.push('size is requied');
if(!req.body || !req.body.user) errors.push('user is requied');
if(errors.length > 0){
res.render('home', {title: 'Home', bag: {body: req.body}} );
}
else{
contract.init_ball([req.body.name, req.body.color, req.body.size, req.body.user], cb_invoke);
}
function cb_invoke(e, a){
console.log('?', e, a);
res.render('home', {title: 'Home', bag: {body: req.body}} );
}
});
*/
module.exports = router;
20 changes: 15 additions & 5 deletions setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
// 1 - Bluemix Production
// 2 - Bluemix Development
// 3 - Localhost Development


var vcap_app = {application_uris: ['']}; //default blank
if(process.env.VCAP_APPLICATION){
vcap_app = JSON.parse(process.env.VCAP_APPLICATION);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// 1. Bluemix Production ////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
if(process.env.VCAP_APP_HOST && process.env.PRODUCTION){
exports.SERVER = {
HOST: process.env.VCAP_APP_HOST,
PORT: process.env.VCAP_APP_PORT,
DESCRIPTION: 'Bluemix - Production'
};
DESCRIPTION: 'Bluemix - Production',
EXTURI: vcap_app.application_uris[0],
};
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -30,7 +35,8 @@ else if(process.env.VCAP_APP_HOST){
exports.SERVER = {
HOST: process.env.VCAP_APP_HOST,
PORT: process.env.VCAP_APP_PORT,
DESCRIPTION: 'Bluemix - Development'
DESCRIPTION: 'Bluemix - Development',
EXTURI: vcap_app.application_uris[0],
};
}

Expand All @@ -41,10 +47,14 @@ else{
exports.SERVER = {
HOST:'localhost',
PORT: 3000,
DESCRIPTION: 'Localhost'
DESCRIPTION: 'Localhost',
EXTURI: 'localhost:3000',
};
}

////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// Common ////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
console.log('env', process.env);

exports.DEBUG = vcap_app;
2 changes: 1 addition & 1 deletion views/template/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ html
script(src='/js/simplestuff1.js')
script(type='text/javascript').
var bag = !{JSON.stringify(bag)}; //throw jade json over to JS
console.log(bag);
console.log('bag', bag);
$(document).ready(function(){

});
Expand Down

0 comments on commit 0e37b8b

Please sign in to comment.