Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const port = 8000
const Gun = require('gun')
function hasValidToken (msg) {
return msg && msg && msg.headers && msg.headers.token && msg.headers.token === 'thisIsTheTokenForReals'
}
// Add listener
Gun.on('opt', function (ctx) {
if (ctx.once) {
return
}
// Check all incoming traffic
ctx.on('in', function (msg) {
var to = this.to
// restrict put
if (msg.put) {
if (hasValidToken(msg)) {
console.log('writing')
to.next(msg)
} else {
console.log('not writing')
}
} else {
to.next(msg)
const port = 8000
const Gun = require('gun')
function hasValidToken (msg) {
return msg && msg.headers && msg.headers.token && msg.headers.token === 'thisIsTheTokenForReals'
}
// Add listener
Gun.on('opt', function (ctx) {
if (ctx.once) {
return
}
// Check all incoming traffic
ctx.on('in', function (msg) {
var to = this.to
// restrict everything with invalid tokens
if (msg.put || msg.get) {
if (hasValidToken(msg)) {
console.log('okay')
to.next(msg)
} else {
console.log('not okay')
console.log(msg)
}
} else {
import ws from 'ws';
const WebSocketServer = ws.Server;
const port: string | number =
process.env.OPENSHIFT_NODEJS_PORT ||
process.env.VCAP_APP_PORT ||
process.env.PORT ||
process.argv[2] ||
8765;
//
// have to do this before instancing gun(?)
const gunPeers: Array<{ send: (msg: any) => void }> = [];
Gun.on('out', function(msg: any) {
// @ts-ignore
this.to.next(msg);
msg = JSON.stringify(msg);
// tslint:disable-next-line
gunPeers.forEach(function(peer) {
peer.send(msg);
});
});
const gun = Gun({
file: 'data',
});
const server = http.createServer((req, res) => {
let insert = '';
if (req.url!.endsWith('gun.js')) {
tests.push(client.run(function(test){
localStorage.clear(); console.log('Clear localStorage!!!');
var env = test.props;
var opt = {peers:['http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun'], wait: 1000};
var pid = location.hash.slice(1);
if (pid) { opt.pid = pid; }
Gun.on('opt', function(ctx) {
this.to.next(ctx);
ctx.on('hi', function(opt) {
document.getElementById('pid').innerHTML = (document.getElementById('pid').innerHTML || "-") + ', ' + this.on.opt.pid;
});
});
var gun = window.gun = Gun(opt);
window.ref = gun.get('holy').get('grail');
}, {i: i += 1, config: config}));
});