forked from IBM-Blockchain-Archive/marbles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4be61f3
Showing
26 changed files
with
1,868 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
**/launchConfigurations | ||
**/node_modules | ||
**/.vscode | ||
**/temp | ||
**/public/logs/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#OBC - JS | ||
|
||
- this is a whole node project atm. obc-js can be found in /utils/obc-js.js | ||
- examples using it in app.js near bottom | ||
|
||
Run: | ||
> npm install | ||
> gulp | ||
|
||
|
||
Alternative Run: | ||
|
||
> npm install | ||
> node app.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
"use strict"; | ||
/* global process */ | ||
/* global __dirname */ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 IBM Corp. | ||
* | ||
* All rights reserved. | ||
* | ||
* Contributors: | ||
* David Huffman - Initial implementation | ||
*******************************************************************************/ | ||
///////////////////////////////////////// | ||
///////////// Setup Node.js ///////////// | ||
///////////////////////////////////////// | ||
var express = require('express'); | ||
var session = require('express-session'); | ||
var compression = require('compression'); | ||
var serve_static = require('serve-static'); | ||
var path = require('path'); | ||
var morgan = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
var http = require('http'); | ||
var app = express(); | ||
var url = require('url'); | ||
var async = require('async'); | ||
var google = require('googleapis'); | ||
var setup = require('./setup'); | ||
var cors = require("cors"); | ||
var fs = require("fs"); | ||
|
||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; | ||
|
||
//// Set Server Parameters //// | ||
var host = (process.env.VCAP_APP_HOST || setup.SERVER.HOST); | ||
var port = (process.env.VCAP_APP_PORT || setup.SERVER.PORT); | ||
|
||
|
||
//////// Pathing and Module Setup //////// | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'jade'); | ||
app.engine('.html', require('jade').__express); | ||
app.use(compression()); | ||
app.use(morgan('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded()); | ||
app.use(cookieParser()); | ||
app.use( serve_static(path.join(__dirname, 'public'), {maxAge: '1d', setHeaders: setCustomCC}) ); //1 day cache | ||
app.use(session({secret:'Somethignsomething1234!test', resave:true, saveUninitialized:true})); | ||
function setCustomCC(res, path) { | ||
if (serve_static.mime.lookup(path) === 'image/jpeg') res.setHeader('Cache-Control', 'public, max-age=2592000'); //30 days cache | ||
else if (serve_static.mime.lookup(path) === 'image/png') res.setHeader('Cache-Control', 'public, max-age=2592000'); | ||
else if (serve_static.mime.lookup(path) === 'image/x-icon') res.setHeader('Cache-Control', 'public, max-age=2592000'); | ||
} | ||
// Enable CORS preflight across the board. | ||
app.options('*', cors()); | ||
app.use(cors()); | ||
|
||
/////////// Configure Webserver /////////// | ||
app.use(function(req, res, next){ | ||
var keys; | ||
console.log('silly', '------------------------------------------ incoming request ------------------------------------------'); | ||
console.log('info', 'New ' + req.method + ' request for', req.url); | ||
req.bag = {}; //create my object for my stuff | ||
req.session.count = eval(req.session.count) + 1; | ||
req.bag.session = req.session; | ||
|
||
var url_parts = url.parse(req.url, true); | ||
req.parameters = url_parts.query; | ||
keys = Object.keys(req.parameters); | ||
if(req.parameters && keys.length > 0) console.log({parameters: req.parameters}); //print request parameters | ||
keys = Object.keys(req.body); | ||
if (req.body && keys.length > 0) console.log({body: req.body}); //print request body | ||
next(); | ||
}); | ||
|
||
//// Router //// | ||
app.use('/', require('./routes/site_router')); | ||
|
||
//////////////////////////////////////////// | ||
////////////// Error Handling ////////////// | ||
//////////////////////////////////////////// | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
app.use(function(err, req, res, next) { // = development error handler, print stack trace | ||
console.log("Error Handeler -", req.url); | ||
var errorCode = err.status || 500; | ||
res.status(errorCode); | ||
req.bag.error = {msg:err.stack, status:errorCode}; | ||
if(req.bag.error.status == 404) req.bag.error.msg = "Sorry, I cannot locate that file"; | ||
res.render('template/error', {bag:req.bag}); | ||
}); | ||
|
||
////////////// Launch ////////////// | ||
var server = app.listen(port, host); //gogo application | ||
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'); | ||
|
||
|
||
|
||
|
||
// ============================================================================================================================ | ||
// ============================================================================================================================ | ||
// ============================================================================================================================ | ||
// ============================================================================================================================ | ||
// ============================================================================================================================ | ||
// ============================================================================================================================ | ||
|
||
// ============================================================================================================================ | ||
// Warning | ||
// ============================================================================================================================ | ||
|
||
// ============================================================================================================================ | ||
// Entering | ||
// ============================================================================================================================ | ||
|
||
// ============================================================================================================================ | ||
// Test Area | ||
// ============================================================================================================================ | ||
var obc = require('./utils/obc-js'); | ||
obc.network('173.193.240.230', 5003, false); //setup network connection for rest endpoint - (host, port, ssl) | ||
obc.load('https://hub.jazz.net/git/averyd/cc_ex02/archive?revstr=master', 'chaincode_dsh', cb_ready); //parse/load chaincode | ||
|
||
function cb_ready(err, contract){ | ||
contract.cc.details.name = { | ||
"url": "https://hub.jazz.net/git/averyd/cc_ex02/chaincode_dsh", | ||
"version": "0.0.1" | ||
}; | ||
obc.save(); | ||
//console.log('contract details:', contract.cc.details); | ||
//contract.init(); | ||
//contract.invoke(["a", "b", "5"]); | ||
//contract.init(); | ||
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* global templatizer */ | ||
///// Gulp Dependencies ///// | ||
var gulp = require('gulp'), | ||
sass = require('gulp-sass'), | ||
concat = require('gulp-concat'), | ||
minifyCss = require('gulp-minify-css'), | ||
rename = require("gulp-rename"), | ||
watch = require('gulp-watch'), | ||
sourcemaps = require('gulp-sourcemaps'), | ||
uglify = require('gulp-uglify'), | ||
spawn = require('child_process').spawn, | ||
node; | ||
|
||
////// Build Tasks /////// | ||
gulp.task('build-sass', function () { | ||
gulp.src('./src/scss/*.scss') | ||
.pipe(sass().on('error', sass.logError)) | ||
.pipe(gulp.dest('./src/scss/temp')) //build them here first | ||
.pipe(concat('main.css')) //concat them all | ||
.pipe(gulp.dest('./public/css')) | ||
.pipe(minifyCss()) //minify | ||
.pipe(rename("main.min.css")) | ||
.pipe(gulp.dest('./public/css')); //dump it here | ||
}); | ||
|
||
////// Run Server Task /////// | ||
gulp.task('server', function() { | ||
if (node) node.kill(); | ||
node = spawn('node', ['app.js'], {stdio: 'inherit'}); //command, file, options | ||
}); | ||
|
||
|
||
////// Watch Tasks ////// | ||
gulp.task('watch-sass', ['build-sass'], function () { | ||
gulp.watch('./src/scss/*.scss', ['build-sass']); | ||
}); | ||
gulp.task('watch-jade', ['build-jade'], function () { | ||
gulp.watch('./views/**/*.js', ['build-jade']); | ||
}); | ||
gulp.task('watch-server', ['server'], function () { | ||
gulp.watch('./routes/**/*.js', ['server']); | ||
gulp.watch('./utils/**/*.js', ['server']); | ||
gulp.watch('./setup.js', ['server']); | ||
gulp.watch('./app.js', ['server']); | ||
}); | ||
|
||
|
||
////// Default ////// | ||
gulp.task('default', ['watch-sass', 'watch-server'], function(){}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
applications: | ||
disk_quota: 1024M | ||
host: blank | ||
name: blank | ||
command: node app.js | ||
path: . | ||
domain: mybluemix.net | ||
instances: 1 | ||
memory: 128M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "iotsm-web", | ||
"version": "0.0.1", | ||
"description": "STB", | ||
"main":"app.js", | ||
"dependencies": { | ||
"express": "4.0.0", | ||
"jade": "1.3.1", | ||
"express-session": "1.2.1", | ||
"compression": "1.4.4", | ||
"serve-static": "1.9.2", | ||
"morgan": "1.1.1", | ||
"cookie-parser": "1.0.1", | ||
"body-parser": "1.0.2", | ||
"debug": "0.7.4", | ||
"cors":"2.5.3", | ||
"async": "0.9.0", | ||
"googleapis": "1.1.3", | ||
"jsrsasign": "4.8.3", | ||
"winston": "0.8.3", | ||
"base64-js" : "0.0.6", | ||
"hashids": "1.0.2", | ||
"nano":"6.1.3", | ||
"unzip2":"0.2.5" | ||
}, | ||
"engines": { | ||
"node": "0.12.0" | ||
}, | ||
"repository": {}, | ||
"devDependencies": { | ||
"gulp": "^3.9.0", | ||
"gulp-sass": "^2.0.4", | ||
"gulp-concat": "*", | ||
"gulp-minify-css": "1.2.1", | ||
"gulp-uglify": "^1.2.0", | ||
"gulp-util": "^3.0.6", | ||
"gulp-watch": "^4.3.4", | ||
"gulp-sourcemaps": "*", | ||
"gulp-rename": "*", | ||
"watchify": "^3.3.1" | ||
} | ||
} |
Oops, something went wrong.