javascript - 应用级拦截的电子代理设置
问题描述
我正在尝试设置一个代理服务器来代理我的电子应用程序中的每个请求,但我似乎无法让请求通过代理。我遵循了文档,我认为这是正确的,但我不知道它是否有效(我在日志中看不到任何内容)
(async () => {
const getPort = require('get-port');
const { setupProxyServer, stopProxyServer } = require('./proxy');
const instance = 'http://localhost:8080';
const PROXY_PORT = await getPort();
await setupProxyServer(instance, PROXY_PORT);
// Modules to control application life and create native browser window
const { app, BrowserWindow, session } = require('electron')
app.commandLine.appendSwitch('proxy-server', PROXY_PORT);
const createWindow = async () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 1800,
height: 1200
})
// Open the DevTools.
if (process.env.DEVTOOLS) mainWindow.webContents.openDevTools();
// and load the index.html of the app.
mainWindow.loadURL(instance);
};
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(async () => {
// session.fromPartition('persist:glide');
createWindow();
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
});
});
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', async () => {
if (process.platform !== 'darwin') app.quit()
await stopProxyServer();
});
})();
中间件设置很好我可以在日志中看到中间件服务器已启动并等待请求。
解决方案
推荐阅读
- node.js - 如何在启用letsencrypt https的情况下连接到节点服务器
- javascript - 如果它与另一个字符串匹配,如何使 JavaScript 更改字符串?
- python-3.x - 一个excel表格列表,我如何组合成一个单行字符串
- firebase - 如何解决它“RangeError(索引):无效值:有效值范围为空:0”在颤动中?
- c++ - 如何通过程序添加到 QAT 。程序使用c++、mfc mdi
- javascript - Laravel 和 Vuetify 未知的自定义元素
- sqlite - 加快 SQLite 中的 COUNT DISTINCT 查询
- http - 如何使用 Wireshark 访问网站?
- java - android java从内部类访问,需要声明final
- python - 从单个 Txt 文件创建多个音频文件