refactor(gateway): 统一 AETHER_GATEWAY_BIND 为 APP_PORT,新增 API Key 前缀配置和启动自举管理员

- 绑定地址固定 0.0.0.0,仅通过 APP_PORT 控制端口,简化 CLI/Docker/systemd/dev.sh/前端代理全链路
- 新增 API_KEY_PREFIX 环境变量,抽取 handlers/shared/api_keys.rs 消除 admin/public 重复逻辑
- 新增 bootstrap_admin.rs,启动时通过 ADMIN_* 环境变量在无管理员时自动创建首个本地管理员
- 前端密码输入改用 type=password,API Key 占位符改为动态前缀
- 删除过时的 pyproject.toml/uv.lock 和旧部署文档
- 更新 .env.example/README 反映新配置项
This commit is contained in:
fawney19
2026-04-11 17:39:02 +08:00
parent a570a77cca
commit 801e16c988
30 changed files with 867 additions and 3929 deletions

View File

@@ -179,8 +179,7 @@
<Input
id="login-password"
v-model="form.password"
type="text"
masked
type="password"
required
placeholder="输入密码"
autocomplete="off"

View File

@@ -174,7 +174,7 @@
</div>
<div class="flex items-center gap-1.5">
<code class="text-xs font-mono text-muted-foreground">
{{ apiKey.key_display || 'sk-****' }}
{{ apiKey.key_display || '****' }}
</code>
<Button
variant="ghost"
@@ -367,7 +367,7 @@
<div class="min-w-0 flex-1 space-y-2">
<div class="flex items-center gap-2">
<code class="inline-flex max-w-[190px] sm:max-w-[240px] truncate rounded-lg bg-muted px-3 py-1.5 text-[11px] font-mono font-semibold text-foreground/90">
{{ apiKey.key_display || 'sk-****' }}
{{ apiKey.key_display || '****' }}
</code>
<Button
variant="ghost"
@@ -846,7 +846,7 @@ async function toggleApiKey(apiKey: AdminApiKey) {
async function deleteApiKey(apiKey: AdminApiKey) {
const confirmed = await confirmDanger(
`确定要删除这个独立余额 Key 吗?\n\n${apiKey.name || apiKey.key_display || 'sk-****'}\n\n此操作无法撤销。`,
`确定要删除这个独立余额 Key 吗?\n\n${apiKey.name || apiKey.key_display || '****'}\n\n此操作无法撤销。`,
'删除独立 Key'
)

View File

@@ -682,7 +682,7 @@
</div>
<div class="flex items-center gap-1 mt-0.5">
<code class="text-xs font-mono text-muted-foreground">
{{ apiKey.key_display || 'sk-****' }}
{{ apiKey.key_display || '****' }}
</code>
<button
class="p-0.5 hover:bg-muted rounded transition-colors"
@@ -1486,7 +1486,7 @@ async function closeNewApiKeyDialog() {
async function deleteApiKey(apiKey: ApiKey) {
const confirmed = await confirmDanger(
`确定要删除这个API Key吗\n\n${apiKey.key_display || 'sk-****'}\n\n此操作无法撤销。`,
`确定要删除这个API Key吗\n\n${apiKey.key_display || '****'}\n\n此操作无法撤销。`,
'删除 API Key'
)

View File

@@ -86,7 +86,7 @@ const developmentSteps = [
},
{
title: '前端',
note: '自动代理到 8084',
note: '自动代理到 APP_PORT默认 8084',
code: 'cd frontend && npm install && npm run dev',
icon: Monitor
}

View File

@@ -1,4 +1,4 @@
import { defineConfig } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { execSync } from 'child_process'
@@ -12,67 +12,71 @@ function getGitVersion(): string {
}
// https://vite.dev/config/
export default defineConfig(({ mode }) => ({
// GitHub Pages 部署时使用仓库名作为 base
base: process.env.GITHUB_PAGES === 'true' ? '/Aether/' : '/',
plugins: [vue()],
define: {
__APP_VERSION__: JSON.stringify(getGitVersion()),
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
export default defineConfig(({ mode }) => {
const rootEnv = loadEnv(mode, path.resolve(__dirname, '..'), '')
const appPort = rootEnv.APP_PORT || process.env.APP_PORT || '8084'
const gatewayTarget = `http://127.0.0.1:${appPort}`
return {
// GitHub Pages 部署时使用仓库名作为 base
base: process.env.GITHUB_PAGES === 'true' ? '/Aether/' : '/',
plugins: [vue()],
define: {
__APP_VERSION__: JSON.stringify(getGitVersion()),
},
},
build: {
// 使用 esbuild 进行压缩(默认)
minify: 'esbuild',
rollupOptions: {
output: {
// 手动分块以优化加载性能
manualChunks: {
// Vue 核心库
'vue-vendor': ['vue', 'vue-router', 'pinia'],
// UI 组件库
'ui-vendor': ['radix-vue', 'lucide-vue-next'],
// 工具
'utils-vendor': ['axios', 'marked', 'dompurify'],
// 图表
'chart-vendor': ['chart.js', 'vue-chartjs'],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
build: {
// 使用 esbuild 进行压缩(默认)
minify: 'esbuild',
rollupOptions: {
output: {
// 手动分块以优化加载性能
manualChunks: {
// Vue 核心
'vue-vendor': ['vue', 'vue-router', 'pinia'],
// UI 组件
'ui-vendor': ['radix-vue', 'lucide-vue-next'],
// 工具库
'utils-vendor': ['axios', 'marked', 'dompurify'],
// 图表库
'chart-vendor': ['chart.js', 'vue-chartjs'],
},
},
},
// esbuild 配置用于移除 console
target: 'es2015',
},
esbuild: {
// 生产环境移除 console 和 debugger
drop: mode === 'production' ? ['console', 'debugger'] : [],
},
server: {
port: 5173,
proxy: {
// 只代理真正的 API 路径;目标端口由根目录 APP_PORT 控制
'/api/': {
target: gatewayTarget,
changeOrigin: true,
secure: false,
},
'/v1/': {
target: gatewayTarget,
changeOrigin: true,
secure: false,
},
'/health': {
target: gatewayTarget,
changeOrigin: true,
secure: false,
},
},
},
// esbuild 配置用于移除 console
target: 'es2015',
},
esbuild: {
// 生产环境移除 console 和 debugger
drop: mode === 'production' ? ['console', 'debugger'] : [],
},
server: {
port: 5173,
proxy: {
// 只代理真正的 API 路径
// 注意:本地开发时后端默认运行在 8084 端口(见 src/config/settings.py
// 如果使用 Docker则通过 APP_PORT 环境变量映射(默认 80
'/api/': {
target: 'http://localhost:8084', // 本地开发端口
changeOrigin: true,
secure: false,
},
'/v1/': {
target: 'http://localhost:8084', // 本地开发端口
changeOrigin: true,
secure: false,
},
'/health': {
target: 'http://localhost:8084', // 本地开发端口
changeOrigin: true,
secure: false,
},
preview: {
port: 5173,
},
},
preview: {
port: 5173,
}
}))
})