index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. var fs = require('fs'),
  2. argv = require('optimist').argv
  3. var Gun = require('gun')
  4. require('gun/sea')
  5. require('gun/lib/path')
  6. require('gun/lib/not')
  7. require('gun/nts')
  8. var ssl = ( argv.s || argv.ssl );
  9. var pass = ( ( argv.w) ? ( argv.w) : undefined );
  10. var sslOptions = {
  11. key: ( ( argv.k || argv.key ) ? fs.readFileSync( argv.k || argv.key ) : undefined ),
  12. cert: ( ( argv.c || argv.cert ) ? fs.readFileSync( argv.c || argv.cert ) : undefined ),
  13. ca: ( ( argv.t || argv.ca ) ? fs.readFileSync( argv.t || argv.ca ) : undefined ),
  14. passphrase: JSON.stringify(pass)
  15. };
  16. var port = ( ( argv.p || argv.port ) ? ( argv.p || argv.port ) : 8080 );
  17. var config = { port: port };
  18. //create the server
  19. if(ssl){
  20. config.key = sslOptions.key;
  21. config.cert = sslOptions.cert;
  22. config.server = require('https').createServer(config, Gun.serve(__dirname));
  23. } else {
  24. config.server = require('http').createServer(Gun.serve(__dirname));
  25. }
  26. global.gun = Gun({web: config.server.listen(config.port)}); //until: 5000, chunk: 10
  27. console.log('Relay peer started on port ' + config.port + ' with /gun');