Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const express = require('express');
- const Gun = require('gun');
- require('gun/nts')
- const port = (process.env.PORT || 8080);
- const app = express();
- app.use(Gun.serve);
- const server = app.listen(port);
- var gun = Gun({
- web: server,
- localStorage: false,
- radisk: false //will not save anything to disk on the server
- });
- global.Gun = Gun; /// make global to `node --inspect` - debug only
- global.gun = gun;
- setInterval(peers,5000)
- function peers(){//this is if you want to know how many peers are connected to your server.
- console.log('Peers: '+ Object.keys(gun._.opt.peers).join(', '))
- }
- const INDEX_HTML = path.join(__dirname,'public/index.html')
- if (process.env.NODE_ENV !== 'production') {//you will have to figure out how this works for your app.
- app.use(express.static('public'));
- app.get('*', function (_, res) {
- res.sendFile(INDEX_HTML);
- });
- }else{
- const indexPath = path.join(__dirname, 'dist/index.html');
- app.use(express.static('dist'));
- app.get('*', function (_, res) {
- res.sendFile(indexPath);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement