From 053b71edc8d63458f0ed16dd32b8ecd8a1ebeddf Mon Sep 17 00:00:00 2001 From: smail Date: Tue, 1 Sep 2026 00:04:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E5=90=91=E5=AF=BC=E5=BC=80=E5=8F=91=E7=8E=AF=E5=A2=83=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fe/src/i18n/i18n.js | 1 + fe/src/utils/axios.js | 2 +- fe/src/views/Setup/Setup.js | 22 +++++++++++++++++++++- fe/vite.config.js | 5 +++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fe/src/i18n/i18n.js b/fe/src/i18n/i18n.js index 3c8f177..88f3dff 100644 --- a/fe/src/i18n/i18n.js +++ b/fe/src/i18n/i18n.js @@ -59,6 +59,7 @@ const lang = { "err_admin_pwd_length": "管理员密码长度必须为 8 到 12 个字节", "admin_pwd_desc": "请输入 8 到 12 个字节的管理员密码", "setup_failed": "初始化操作失败,请查看终端日志", + "setup_service_unavailable": "初始化服务未启动,请先启动 Smail 后端服务", "setOther": "其他设置", "welcome": "欢迎", "next": "下一步", diff --git a/fe/src/utils/axios.js b/fe/src/utils/axios.js index 00c2b5f..e92203c 100644 --- a/fe/src/utils/axios.js +++ b/fe/src/utils/axios.js @@ -53,7 +53,7 @@ function isSetupRequest(config) { } catch (error) { path = rawUrl } - return path === '/api/setup' || path === '/api/v1/setup' + return path === '/api/setup' || path === '/api/v1/setup' || path === '/__smail_setup_bootstrap' } http.interceptors.response.use(async (response) => { diff --git a/fe/src/views/Setup/Setup.js b/fe/src/views/Setup/Setup.js index 398e27e..0cb19d0 100644 --- a/fe/src/views/Setup/Setup.js +++ b/fe/src/views/Setup/Setup.js @@ -14,7 +14,27 @@ import {http} from "@/utils/axios"; import {buildFinalURL as buildSetupFinalURL, probeService} from './SetupNavigation.js' -const setupRequest = (payload) => http.post("/api/v1/setup", payload).then((response) => { +let setupBootstrapPromise = null + +const ensureSetupSession = () => { + if (!import.meta.env.DEV) { + return Promise.resolve() + } + + if (!setupBootstrapPromise) { + setupBootstrapPromise = http.get("/__smail_setup_bootstrap").catch((error) => { + setupBootstrapPromise = null + if (error?.response?.status === 500 || !error?.response) { + throw new Error(lang.setup_service_unavailable) + } + throw error + }) + } + + return setupBootstrapPromise +} + +const setupRequest = (payload) => ensureSetupSession().then(() => http.post("/api/v1/setup", payload)).then((response) => { if (!response || typeof response.errorNo !== "number") { throw new Error(lang.setup_failed) } diff --git a/fe/vite.config.js b/fe/vite.config.js index 374aa76..068cdb1 100644 --- a/fe/vite.config.js +++ b/fe/vite.config.js @@ -36,6 +36,11 @@ export default defineConfig(({ mode }) => { "/attachments": { target: backendUrl, changeOrigin: false + }, + "/__smail_setup_bootstrap": { + target: backendUrl, + changeOrigin: false, + rewrite: () => "/" } } }