From 6d091aeb4d4f56c52fdb8601b552ad04530c06bb Mon Sep 17 00:00:00 2001 From: W1NDes Date: Thu, 26 Feb 2026 05:34:05 +0800 Subject: [PATCH] =?UTF-8?q?Fix(webapp):=20=E4=BF=AE=E5=A4=8Delectron=20htt?= =?UTF-8?q?p=20url=E5=92=8C=E8=AF=81=E4=B9=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复electron对于http的固定url问题 - 增加对于证书的容忍性(介于本地客户端的情况) --- webapp/packages/main/src/config.ts | 5 ++++- webapp/packages/main/src/index.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/webapp/packages/main/src/config.ts b/webapp/packages/main/src/config.ts index b295c5eae..b308d778e 100644 --- a/webapp/packages/main/src/config.ts +++ b/webapp/packages/main/src/config.ts @@ -9,9 +9,12 @@ const file = fs.readFileSync(path.join(alasPath, './config/deploy.yaml'), 'utf8' const config = yaml.parse(file); const PythonExecutable = config.Deploy.Python.PythonExecutable; const WebuiPort = config.Deploy.Webui.WebuiPort.toString(); +const WebuiSSLKey = config.Deploy.Webui.WebuiSSLKey; +const WebuiSSLCert = config.Deploy.Webui.WebuiSSLCert; +const sslEnabled = WebuiSSLKey && WebuiSSLCert; export const pythonPath = (path.isAbsolute(PythonExecutable) ? PythonExecutable : path.join(alasPath, PythonExecutable)); -export const webuiUrl = `http://127.0.0.1:${WebuiPort}`; +export const webuiUrl = `${sslEnabled ? 'https' : 'http'}://127.0.0.1:${WebuiPort}`; export const webuiPath = 'gui.py'; export const webuiArgs = ['--port', WebuiPort, '--electron']; export const dpiScaling = Boolean(config.Deploy.Webui.DpiScaling) || (config.Deploy.Webui.DpiScaling === undefined) ; diff --git a/webapp/packages/main/src/index.ts b/webapp/packages/main/src/index.ts index e034861a5..abda17aa7 100644 --- a/webapp/packages/main/src/index.ts +++ b/webapp/packages/main/src/index.ts @@ -5,6 +5,17 @@ import {webuiArgs, webuiPath, dpiScaling} from '/@/config'; const path = require('path'); +// Allow self-signed certificates for local HTTPS connections +app.on('certificate-error', (event, _webContents, url, _error, _certificate, callback) => { + // Only allow for local connections + if (url.startsWith('https://127.0.0.1') || url.startsWith('https://localhost')) { + event.preventDefault(); + callback(true); + } else { + callback(false); + } +}); + const isSingleInstance = app.requestSingleInstanceLock(); if (!isSingleInstance) { @@ -52,6 +63,16 @@ const createWindow = async () => { }, }); + // Ignore certificate errors for local connections (domain mismatch) + mainWindow.webContents.session.setCertificateVerifyProc((request, callback) => { + const {hostname} = new URL(request.hostname.includes('://') ? request.hostname : `https://${request.hostname}`); + if (hostname === '127.0.0.1' || hostname === 'localhost') { + callback(0); // 0 = success, ignore certificate errors for local + } else { + callback(-3); // -3 = use default verification + } + }); + /** * If you install `show: true` then it can cause issues when trying to close the window. * Use `show: false` and listener events `ready-to-show` to fix these issues.