I am using of some of the npm modules which are making get request behind the scenes to pull some data from websites. But there is no option or setting to set proxy for those requests, so I want to know how to set proxy for entire electron app so that all the requests go through that proxy?
Setting Proxy for Electron App
Asked Answered
Using request:
Use environment variables :
process.env.HTTP_PROXY = 'http://192.168.0.36:3128'
Using Axios:
Install this package :
npm install https-proxy-agent
Then :
const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');
let config = {}
config.httpsAgent = new HttpsProxyAgent('http://192.168.0.36:3128')
config.url = 'https://example.com'
config.method = 'GET'
axios(config).then(...).catch(...)
Electron app
For the wall app (like IMG SRC in HTML), you can use command line switches supported by Electron :
const { app } = require('electron')
app.commandLine.appendSwitch('proxy-server', '172.17.0.2:3128')
app.on('ready', () => {
// Your code here
})
See documentation
© 2022 - 2024 — McMap. All rights reserved.