parent
96d1175834
commit
245c0f0c27
@ -0,0 +1,15 @@ |
||||
// log rpc activity
|
||||
module.exports = createLoggerMiddleware |
||||
|
||||
function createLoggerMiddleware({ origin }) { |
||||
return function loggerMiddleware (req, res, next, end) { |
||||
next((cb) => { |
||||
if (res.error) { |
||||
log.error('Error in RPC response:\n', res) |
||||
} |
||||
if (req.isMetamaskInternal) return |
||||
log.info(`RPC (${origin}):`, req, '->', res) |
||||
cb() |
||||
}) |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
// append dapp origin domain to request
|
||||
module.exports = createOriginMiddleware |
||||
|
||||
function createOriginMiddleware({ origin }) { |
||||
return function originMiddleware (req, res, next, end) { |
||||
req.origin = originDomain |
||||
next() |
||||
} |
||||
} |
@ -0,0 +1,13 @@ |
||||
|
||||
module.exports = createProviderMiddleware |
||||
|
||||
// forward requests to provider
|
||||
function createProviderMiddleware({ provider }) { |
||||
return (req, res, next, end) => { |
||||
provider.sendAsync(req, (err, _res) => { |
||||
if (err) return end(err) |
||||
res.result = _res.result |
||||
end() |
||||
}) |
||||
} |
||||
} |
Loading…
Reference in new issue