Setting Proxy for Electron App
Asked Answered
G

1

10

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?

Galvanoscope answered 12/4, 2018 at 23:50 Comment(0)
W
2

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

Whale answered 25/10, 2019 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.