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.