我的 HTML 页面中有以下代码
Gun.on('opt', function (ctx) {
if (ctx.once) {
return
}
this.to.next(ctx)
window.auth = ctx.opt.auth
ctx.on('get', function (msg) {
msg.auth = window.auth
this.to.next(msg)
})
ctx.on('put', function (msg) {
msg.put.auth = window.auth
this.to.next(msg)
})
})
var gun = Gun({
peers: ['http://localhost:8765/gun'],
auth: {
user: 'mroon',
password: 'titi'
}
})
在服务器上,我只是观察请求
Gun.on('create', function(db) {
console.log('gun created')
this.to.next(db);
db.on('get', function(request) {
// this request contains the auth attribute from the client
this.to.next(request);
});
db.on('put', function(request) {
// this request does not contain the auth attribute from the client
this.to.next(request);
});
});
每次我使用gun.get('someAttribute')
服务器上的请求查询图形时都包含该auth
属性。
但是当gun.get('someAttribute').put({attribute: 'my new value'})
调用 a 时,服务器上的请求不包含该auth
属性。
如何将auth
属性添加到put
请求中,以使所有对等方也能获得它?