代理功能,作者:buvta

This commit is contained in:
haiyangcui
2020-11-08 00:13:08 +01:00
parent c3a4cf5cc5
commit 4136b0f3ce
2 changed files with 18 additions and 1 deletions

View File

@@ -24,6 +24,7 @@
"cors": "^2.8.5",
"dexie": "^3.0.2",
"electron-localshortcut": "^3.2.1",
"electron-proxy-agent": "^1.2.0",
"electron-updater": "^4.3.5",
"element-ui": "^2.14.0",
"express": "^4.17.1",
@@ -32,10 +33,12 @@
"iptv-playlist-parser": "^0.5.0",
"m3u": "0.0.2",
"m3u8-parser": "^4.5.0",
"memcached": "^2.2.2",
"modern-normalize": "^1.0.0",
"mousetrap": "^1.6.5",
"qrcode.vue": "^1.7.0",
"randomstring": "^1.1.5",
"session": "^0.1.0",
"v-fit-columns": "^0.2.0",
"vue": "^2.6.12",
"vue-clickaway": "^2.2.2",

View File

@@ -4,9 +4,23 @@ import parser from 'fast-xml-parser'
import cheerio from 'cheerio'
import { Parser as M3u8Parser } from 'm3u8-parser'
// axios使用系统代理 https://evandontje.com/2020/04/02/automatic-system-proxy-configuration-for-electron-applications/
// xgplayer使用chromium代理设置浏览器又默认使用系统代理 https://www.chromium.org/developers/design-documents/network-settings
// 要在设置中添加代理设置可参考https://stackoverflow.com/questions/37393248/how-connect-to-proxy-in-electron-webview
var http = require('http')
var https = require('http')
const { remote } = require('electron')
var win = remote.getCurrentWindow()
var session = win.webContents.session
var ElectronProxyAgent = require('electron-proxy-agent')
// use ElectronProxyAgent as http and https globalAgents
http.globalAgent = https.globalAgent = new ElectronProxyAgent(session)
// axios.get('https://api.my-ip.io/ip').then(res => console.log(res))
// 请求超时时限
axios.defaults.timeout = 5000
axios.defaults.timeout = 10000 // 可能使用代理,增长超时
// 重试次数共请求3次
axios.defaults.retry = 2