electron拦截请求实现跨域
protocol.interceptHttpProtocol('http', (req, cb) => {
if (req.url.includes('common')) {
console.log(req)
let resp = {
"url": req.url,
'session': session.fromPartition(Math.random() + ''),
'uploadData': {
contentType: '',
data: ''
}
}
if (req.uploadData.[0]) {
let bff = req.uploadData.[0].bytes
console.log(bff.toString('utf-8'))
resp.uploadData = {
contentType: 'application/json',
data: bff.toString('utf-8')
}
}
cb(resp)
} else {
cb({
"url": req.url,
'session': session.fromPartition(Math.random() + '')
})
}
})