feat: 优化网络绑定配置支持外部访问

主要修改点:
1. 网络绑定调整
   - .env.example: WEB_HOST/VITE_WEB_HOST 从 127.0.0.1 改为 0.0.0.0
   - server/src/app/core/config.py: 默认 web_host 从 127.0.0.1 改为 0.0.0.0
   - web/package.json: Vite 脚本 host 从 127.0.0.1 改为 0.0.0.0
   - web/vite.config.js: normalizeState 中 WEB_HOST 默认值从 127.0.0.1 改为 0.0.0.0

2. CORS 配置扩展
   - .env.example: CORS_ORIGINS 添加 http://0.0.0.0:5173

3. Shell 脚本权限修复
   - server/start.sh, start.sh: 添加可执行权限 (644 -> 755)

4. Setup 表单与验证逻辑简化
   - web/src/composables/useSetupView.js:
     - 新增 readCurrentWebEndpoint() 从 window.location 自动检测当前 web host/port
     - 简化 runtimeInputsReady: 移除 web_host/web_port 必填验证,仅保留 server_host/server_port
     - 简化 buildRuntimeFingerprint(): 移除 web_host/web_port
     - buildPayload() 改用 readCurrentWebEndpoint() 解析 web 配置
   - web/vite.config.js:
     - 新增 resolveRuntimePayload(): 运行时解析 web_host/web_port
     - 移除 validateRuntimePayload() 中的 web_host/web_port 字段验证
     - 移除 testRuntimePorts() 中 web 端口冲突检测逻辑
     - 移除 canReuseCurrentWebPort() 函数

5. CSS 清理
   - web/src/assets/styles/views/setup-view.css: 移除未使用的 .setup-summary-grid 和 .setup-summary-item 样式
This commit is contained in:
2026-05-08 09:27:45 +08:00
parent adda87a01d
commit 828e8f5aaf
11 changed files with 61 additions and 132 deletions

View File

@@ -1,6 +1,25 @@
import { computed, reactive, ref, watch } from 'vue'
function readCurrentWebEndpoint(initialState) {
if (typeof window === 'undefined') {
return {
host: initialState?.web?.host || '0.0.0.0',
port: Number(initialState?.web?.port || 5173)
}
}
const fallbackPort = Number(initialState?.web?.port || 5173)
const port = Number(window.location.port || fallbackPort)
return {
host: window.location.hostname || initialState?.web?.host || '0.0.0.0',
port: Number.isInteger(port) && port > 0 ? port : fallbackPort
}
}
function createForm(initialState) {
const currentWeb = readCurrentWebEndpoint(initialState)
return {
company_name: initialState?.company?.name || '',
company_code: initialState?.company?.code || '',
@@ -8,8 +27,8 @@ function createForm(initialState) {
admin_username: '',
admin_password: '',
admin_password_confirm: '',
web_host: initialState?.web?.host || '127.0.0.1',
web_port: initialState?.web?.port || 5173,
web_host: currentWeb.host,
web_port: currentWeb.port,
server_host: initialState?.server?.host || '127.0.0.1',
server_port: initialState?.server?.port || 8000,
postgres_host: initialState?.database?.host || '127.0.0.1',
@@ -22,6 +41,13 @@ function createForm(initialState) {
}
function buildPayload(form) {
const currentWeb = readCurrentWebEndpoint({
web: {
host: form.web_host,
port: form.web_port
}
})
return {
company_name: form.company_name.trim(),
company_code: form.company_code.trim(),
@@ -29,8 +55,8 @@ function buildPayload(form) {
admin_username: form.admin_username.trim(),
admin_password: String(form.admin_password || ''),
admin_password_confirm: String(form.admin_password_confirm || ''),
web_host: form.web_host.trim(),
web_port: Number(form.web_port),
web_host: currentWeb.host,
web_port: currentWeb.port,
server_host: form.server_host.trim(),
server_port: Number(form.server_port),
postgres_host: form.postgres_host.trim(),
@@ -44,8 +70,6 @@ function buildPayload(form) {
function buildRuntimeFingerprint(form) {
return JSON.stringify({
web_host: form.web_host.trim(),
web_port: String(form.web_port).trim(),
server_host: form.server_host.trim(),
server_port: String(form.server_port).trim()
})
@@ -112,9 +136,7 @@ export function useSetupView(props, emit) {
})
const runtimeInputsReady = computed(() => {
return Boolean(
form.web_host.trim() &&
String(form.web_port).trim() &&
form.server_host.trim() &&
form.server_host.trim() &&
String(form.server_port).trim()
)
})
@@ -151,7 +173,7 @@ export function useSetupView(props, emit) {
id: 'runtime',
index: '03',
title: '运行端口',
desc: '单独检测 Web 与后端端口占用。',
desc: 'Web 端口跟随当前启动实例,只检测后端端口占用。',
complete: runtimeReady.value
},
{
@@ -168,38 +190,15 @@ export function useSetupView(props, emit) {
const runtimeEndpoints = computed(() => [
{
label: 'Web',
label: 'Web 当前访问',
value: `${form.web_host}:${form.web_port}`
},
{
label: 'Server',
label: 'Server 待启动',
value: `${form.server_host}:${form.server_port}`
}
])
const summaryItems = computed(() => [
{
label: '企业信息',
detail: form.company_name.trim() || '未完成',
complete: companyReady.value
},
{
label: '管理员安全',
detail: form.admin_username.trim() || form.admin_email.trim() || '未完成',
complete: adminReady.value
},
{
label: '运行端口',
detail: `${form.web_host}:${form.web_port} / ${form.server_host}:${form.server_port}`,
complete: runtimeReady.value
},
{
label: '数据库',
detail: `${form.postgres_host}:${form.postgres_port}/${form.postgres_db}`,
complete: databaseReady.value
}
])
const currentTestMessage = computed(() => {
if (activeSection.value === 'runtime') {
return props.runtimeTestMessage
@@ -290,7 +289,7 @@ export function useSetupView(props, emit) {
if (activeSection.value === 'runtime') {
if (!runtimeInputsReady.value) {
return '请先填写 Web 与 Server 的主机和端口。'
return '请先填写 Server 的主机和端口。'
}
if (!props.runtimeTestPassed) {
@@ -375,7 +374,6 @@ export function useSetupView(props, emit) {
showTestAction,
submitForm,
submitHint,
summaryItems,
testButtonIcon,
testButtonLabel,
testSetup

View File

@@ -38,7 +38,7 @@ function readClientBootstrapState() {
admin_email: env.VITE_ADMIN_EMAIL || ''
},
web: {
host: env.VITE_WEB_HOST || '127.0.0.1',
host: env.VITE_WEB_HOST || '0.0.0.0',
port: Number(env.VITE_WEB_PORT || 5173)
},
server: {