In my electron app, I have coded a RestClient which is executed in main and renderer process. The first request, done in the main process, is done with the net library from electron and it successfully uses the system proxy settings.
The next request, executed in renderer process cannot use net library, because this belongs to main only. Therefore I switch to normal https request, but this does not use system proxy settings.
Is there a way to use the system proxy in the renderer process?
Edit: Maybe a more general question: What is the best practise in electron to make web requests? Is there some standard way to use http/https, request, net or fetch? Which way would use the system proxy?
i tested this on windows and it runs smoothly with fetch() in the renderer
but i think best practice at this point is to send a message from renderer process via ipcRenderer to the main process.
so in your renderer process send a message with
const ipc = require('electron').ipcRenderer;
ipc.send('hello','a string', 10);
and in your main process receive the message and make your api request like the first
ipc.on('fromMain', (event, messages) => {
// do your api request and send data back
}
after this send the data back to the renderer process
why?
Advantages: strict separation of frontend and backend, only one method for API query and of course "don't repeat yourself"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With