SHARE
TWEET

Untitled

a guest Jun 26th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const express = require('express');
  3.  
  4. const Gun = require('gun');
  5. require('gun/nts')
  6.  
  7. const port = (process.env.PORT || 8080);
  8.  
  9. const app = express();
  10. app.use(Gun.serve);
  11.  
  12. const server = app.listen(port);
  13.  
  14. var gun = Gun({
  15.   web: server,
  16.   localStorage: false,
  17.   radisk: false //will not save anything to disk on the server
  18. });
  19. global.Gun = Gun; /// make global to `node --inspect` - debug only
  20. global.gun = gun;
  21.  
  22. setInterval(peers,5000)
  23. function peers(){//this is if you want to know how many peers are connected to your server.
  24.   console.log('Peers: '+ Object.keys(gun._.opt.peers).join(', '))
  25. }
  26.  
  27.  
  28. const INDEX_HTML = path.join(__dirname,'public/index.html')
  29. if (process.env.NODE_ENV !== 'production') {//you will have to figure out how this works for your app.
  30.   app.use(express.static('public'));
  31.   app.get('*', function (_, res) {
  32.     res.sendFile(INDEX_HTML);
  33.   });
  34. }else{
  35.   const indexPath = path.join(__dirname, 'dist/index.html');
  36.   app.use(express.static('dist'));
  37.   app.get('*', function (_, res) {
  38.     res.sendFile(indexPath);
  39.   });
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top