From 387eb8322729e0f3aa71bd09b8cdd913f3cdcde8 Mon Sep 17 00:00:00 2001 From: Mengling Ding Date: Thu, 16 Jan 2025 11:25:21 -0600 Subject: [PATCH] feat: change webui to be a https client --- .gitignore | 3 ++- webui/generate-cert.sh | 16 ++++++++++++++++ webui/package.json | 4 ++-- webui/vite.config.ts | 11 ++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100755 webui/generate-cert.sh diff --git a/.gitignore b/.gitignore index 42952add..054d22f3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ webui/src/axios /cmd/cxl-host/cxl-host-accounts.json # Ignore the module files -webui/node_modules/ \ No newline at end of file +webui/node_modules/ +webui/incoming/ \ No newline at end of file diff --git a/webui/generate-cert.sh b/webui/generate-cert.sh new file mode 100755 index 00000000..29343445 --- /dev/null +++ b/webui/generate-cert.sh @@ -0,0 +1,16 @@ +# Copyright (c) 2025 Seagate Technology LLC and/or its Affiliates + +#!/bin/bash + +# Define certificate file paths +KEY_FILE="incoming/key.pem" +CERT_FILE="incoming/cert.pem" + +# Create the directory if it doesn't exist +mkdir -p incoming + +# Generate self-signed certificate +openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout $KEY_FILE -out $CERT_FILE -subj "/CN=localhost" + +echo "Self-signed certificate generated: $CERT_FILE" +echo "Private key generated: $KEY_FILE" \ No newline at end of file diff --git a/webui/package.json b/webui/package.json index 173221ca..d7a08ef6 100644 --- a/webui/package.json +++ b/webui/package.json @@ -3,8 +3,8 @@ "version": "1.x.x", "private": true, "scripts": { - "dev": "vite", - "build": "vue-tsc --noEmit && vite build", + "dev": "sh generate-cert.sh && vite", + "build": "vue-tsc --noEmit && sh generate-cert.sh && vite build", "preview": "vite preview", "lint": "eslint . --fix --ignore-path .gitignore" }, diff --git a/webui/vite.config.ts b/webui/vite.config.ts index 184ca658..acaca005 100644 --- a/webui/vite.config.ts +++ b/webui/vite.config.ts @@ -9,6 +9,7 @@ import fs from 'fs'; // Utilities import { defineConfig } from 'vite' import { fileURLToPath, URL } from 'node:url' +import path from 'path'; const configYaml = fs.readFileSync('./config.yaml', 'utf8'); @@ -36,10 +37,10 @@ export default defineConfig({ }, }), ], - define: { + define: { 'process.env': { BASE_PATH: parsedConfig.api.base_path, - } + } }, resolve: { alias: { @@ -56,7 +57,11 @@ export default defineConfig({ ], }, server: { - host:'0.0.0.0', + host: '0.0.0.0', port: 3000, + https: { + key: fs.existsSync(path.resolve(__dirname, 'incoming/key.pem')) ? fs.readFileSync(path.resolve(__dirname, 'incoming/key.pem')) : undefined, + cert: fs.existsSync(path.resolve(__dirname, 'incoming/cert.pem')) ? fs.readFileSync(path.resolve(__dirname, 'incoming/cert.pem')) : undefined + }, }, })