diff --git a/fe/src/i18n/i18n.js b/fe/src/i18n/i18n.js index 3c8f1772..88f3dffc 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 00c2b5ff..e92203c9 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 398e27ed..0cb19d0b 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 374aa760..068cdb1a 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: () => "/" } } }