summaryrefslogtreecommitdiff
path: root/backend
authorMichael Krelin <hacker@klever.net>2014-07-01 17:49:10 (UTC)
committer Michael Krelin <hacker@klever.net>2014-07-01 17:49:10 (UTC)
commita6e5df547739ac91055ae0ae4928447c9ec50a98 (patch) (unidiff)
treee5d2e63d8c782bb471fa95bd8c7d6d21e3c322b0 /backend
parentb9ee39b810aae10da83534776028585309b53a24 (diff)
downloadclipperz-a6e5df547739ac91055ae0ae4928447c9ec50a98.zip
clipperz-a6e5df547739ac91055ae0ae4928447c9ec50a98.tar.gz
clipperz-a6e5df547739ac91055ae0ae4928447c9ec50a98.tar.bz2
clipperz middleware as a router instead of two separate handlers and staticHEADmaster
Diffstat (limited to 'backend') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/node/src/app.js7
-rw-r--r--backend/node/src/clipperz.js6
2 files changed, 10 insertions, 3 deletions
diff --git a/backend/node/src/app.js b/backend/node/src/app.js
index bbc62f8..09dcfac 100644
--- a/backend/node/src/app.js
+++ b/backend/node/src/app.js
@@ -22,30 +22,31 @@ var CLIPPERZ = require('./clipperz');
22var CONF = require('./conf'); 22var CONF = require('./conf');
23var clipperz = CLIPPERZ({ 23var clipperz = CLIPPERZ({
24 psql: CONF.psql||'postgresql:///clipperz', 24 psql: CONF.psql||'postgresql:///clipperz',
25 logger: LOGGER, 25 logger: LOGGER,
26 dump_template: PATH.join(__dirname,'htdocs/beta/index.html') 26 dump_template: PATH.join(__dirname,'htdocs/beta/index.html')
27}); 27});
28 28
29 29
30var app = EXPRESS(); 30var app = EXPRESS();
31 31
32app.set('port', process.env.PORT || 3000); 32app.set('port', process.env.PORT || 3000);
33app.use(require('morgan')('dev')); 33app.use(require('morgan')('dev'));
34app.use(require('body-parser').urlencoded({extended:true})); 34app.use(require('body-parser').urlencoded({extended:true}));
35app.use(require('cookie-parser')('your secret here')); 35app.use(require('cookie-parser')('your secret here'));
36app.use(require('express-session')({secret:'99 little bugs in the code', key:'sid', store: clipperz.session_store(), resave: false, saveUninitialized: false })); 36app.use(require('express-session')({secret:'99 little bugs in the code', key:'sid', store: clipperz.session_store(), resave: false, saveUninitialized: false }));
37 37
38app.post('/json',clipperz.json); 38/* Like this: */
39app.get('/dump',clipperz.dump); 39app.use(clipperz.router);
40/* Or this: */
41app.use('/clz/',clipperz.router);
40 42
41app.use(EXPRESS.static(PATH.join(__dirname, 'htdocs/')));
42if ('development' == app.get('env')) { 43if ('development' == app.get('env')) {
43 app.use(require('express-error-with-sources')()); 44 app.use(require('express-error-with-sources')());
44} 45}
45 46
46 47
47 48
48 49
49HTTP.createServer(app).listen(app.get('port'), function(){ 50HTTP.createServer(app).listen(app.get('port'), function(){
50 LOGGER.info({port:app.get('port')},"Listener established"); 51 LOGGER.info({port:app.get('port')},"Listener established");
51}); 52});
diff --git a/backend/node/src/clipperz.js b/backend/node/src/clipperz.js
index 842de31..2a3df73 100644
--- a/backend/node/src/clipperz.js
+++ b/backend/node/src/clipperz.js
@@ -1,20 +1,22 @@
1var FS = require('fs'); 1var FS = require('fs');
2var CRYPTO = require('crypto'); 2var CRYPTO = require('crypto');
3var BIGNUM = require('bignum'); 3var BIGNUM = require('bignum');
4var ASYNC = require('async'); 4var ASYNC = require('async');
5var EXPRESS = require('express');
6var PATH = require('path');
5 7
6var express_store = require('express-session').Store; 8var express_store = require('express-session').Store;
7 9
8function clipperz_hash(v) { 10function clipperz_hash(v) {
9 return CRYPTO.createHash('sha256').update( 11 return CRYPTO.createHash('sha256').update(
10 CRYPTO.createHash('sha256').update(v).digest('binary') 12 CRYPTO.createHash('sha256').update(v).digest('binary')
11 ).digest('hex'); 13 ).digest('hex');
12}; 14};
13function clipperz_random() { 15function clipperz_random() {
14 for(var r = '';r.length<64;r+=''+BIGNUM(Math.floor(Math.random()*1e18)).toString(16)); 16 for(var r = '';r.length<64;r+=''+BIGNUM(Math.floor(Math.random()*1e18)).toString(16));
15 return r.substr(0,64); 17 return r.substr(0,64);
16}; 18};
17function clipperz_store(PG) { 19function clipperz_store(PG) {
18 var rv = function(o) { express_store.call(this,o); } 20 var rv = function(o) { express_store.call(this,o); }
19 rv.prototype.get = function(sid,cb) { PG.Q( 21 rv.prototype.get = function(sid,cb) { PG.Q(
20 "SELECT s_data FROM clipperz.thesession WHERE s_id=$1",[sid], 22 "SELECT s_data FROM clipperz.thesession WHERE s_id=$1",[sid],
@@ -566,19 +568,23 @@ var CLIPPERZ = module.exports = function(CONFIG) {
566 var ojs = { users: { 568 var ojs = { users: {
567 catchAllUser: { __masterkey_test_value__: 'masterkey', s: n123, v: n123 } 569 catchAllUser: { __masterkey_test_value__: 'masterkey', s: n123, v: n123 }
568 } }; 570 } };
569 r.u.d.records = r.records; 571 r.u.d.records = r.records;
570 ojs.users[r.u.u] = r.u.d; 572 ojs.users[r.u.u] = r.u.d;
571 res.send(r.html.replace('/*offline_data_placeholder*/', 573 res.send(r.html.replace('/*offline_data_placeholder*/',
572 "_clipperz_dump_data_="+JSON.stringify(ojs) 574 "_clipperz_dump_data_="+JSON.stringify(ojs)
573 +";" 575 +";"
574 +"Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.Offline();" 576 +"Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.Offline();"
575 +"Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();")); 577 +"Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();"));
576 }); 578 });
577 } 579 }
578 580
579 }; 581 };
580 rv.__defineGetter__('session_store',function(){ return function(o) { return new (clipperz_store(PG))(o) } }); 582 rv.__defineGetter__('session_store',function(){ return function(o) { return new (clipperz_store(PG))(o) } });
581 583
584 (rv.router = require('express').Router())
585 .post('/json',rv.json).get('/dump',rv.dump)
586 .use(EXPRESS.static(PATH.join(__dirname,'htdocs/')));
587
582 return rv; 588 return rv;
583 589
584}; 590};