1
1
var Gun = require ( "gun/gun" ) ;
2
+ //require("./src/sea");
2
3
var compress = require ( "compression" ) ;
3
4
var commandLineArgs = require ( "command-line-args" ) ;
4
5
var blocked = require ( "./blocked" ) ;
@@ -9,9 +10,10 @@ var options = commandLineArgs([
9
10
{ name : "score" , alias : "s" , type : Boolean } ,
10
11
{ name : "evict" , alias : "e" , type : Boolean } ,
11
12
{ name : "debug" , alias : "d" , type : Boolean } ,
12
- { name : "port" , alias : "p" , type : Number , defaultValue : 3333 } ,
13
+ { name : "port" , alias : "p" , type : Number , defaultValue : null } ,
13
14
{ name : "host" , alias : "h" , type : String , defaultValue : "127.0.0.1" } ,
14
- { name : "peer" , alias : "c" , multiple : true , type : String }
15
+ { name : "peer" , alias : "c" , multiple : true , type : String } ,
16
+ { name : "until" , alias : "u" , multiple : true , type : Number , defaultValue : 5000 }
15
17
] ) ;
16
18
17
19
process . env . GUN_ENV = process . env . GUN_ENV || options . debug ? "debug" : undefined ;
@@ -39,23 +41,39 @@ var path = require("path");
39
41
var express = require ( "express" ) ;
40
42
var router = express . Router ( ) ;
41
43
var init = require ( "notabug-peer" ) . default ;
42
- var app = express ( ) ;
43
- var web = app . listen ( options . port , options . host ) ;
44
+ var web ;
44
45
45
- router . use ( compress ( ) ) ;
46
- router . use ( express . static ( path . join ( __dirname , "build" ) ) ) ;
47
- app . use ( router ) ;
46
+ if ( options . port ) {
47
+ var app = express ( ) ;
48
+ web = app . listen ( options . port , options . host ) ;
48
49
49
- app . get ( "/*" , function ( req , res ) {
50
- res . sendFile ( path . join ( __dirname , "build" , "index.html" ) ) ;
51
- } ) ;
50
+ router . use ( compress ( ) ) ;
51
+ router . use ( express . static ( path . join ( __dirname , "build" ) ) ) ;
52
+ app . use ( router ) ;
53
+
54
+ app . get ( "/*" , function ( req , res ) {
55
+ res . sendFile ( path . join ( __dirname , "build" , "index.html" ) ) ;
56
+ } ) ;
57
+ }
52
58
53
- init ( {
59
+ var nab = init ( {
54
60
blocked,
55
61
peers : options . peer ,
56
62
persist : options . persist ,
57
63
disableValidation : options . disableValidation ,
58
64
scoreThingsForPeers : options . score ,
65
+ until : options . until ,
59
66
super : true ,
60
67
web
61
68
} ) ;
69
+
70
+ if ( options . persist || ! options . port ) {
71
+ nab . watchListing ( { days : 1 } ) ;
72
+ setInterval ( function ( ) {
73
+ nab . watchListing ( { days : 1 } ) ;
74
+ } , 1000 * 60 * 60 ) ;
75
+ }
76
+
77
+ if ( options . persist ) {
78
+ nab . gun . get ( "nab/things" ) . map ( ) . get ( "data" ) . on ( function ( ) { } ) ;
79
+ }
0 commit comments