添加安装部署脚本

This commit is contained in:
admin
2026-05-11 10:41:36 +08:00
parent eae665d66f
commit ddb8746954
25 changed files with 1043 additions and 1 deletions
+1
View File
@@ -8,6 +8,7 @@
</head>
<body>
<div id="app"></div>
<script src="/config.js"></script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+8
View File
@@ -0,0 +1,8 @@
// 运行期注入的配置文件
// Vite 构建时此文件原样拷贝到 dist/;nginx 容器启动时由 docker-entrypoint.d/40-inject-config.sh
// 将 __API_BASE_URL__ 替换为真实地址(来自 API_BASE_URL 环境变量)
//
// 本地 dev 模式占位符不会被替换,request.ts 会自动 fallback 到 VITE_API_BASE_URL
window.__APP_CONFIG__ = {
apiBaseUrl: '__API_BASE_URL__',
};
+15 -1
View File
@@ -13,7 +13,21 @@ interface RequestOptions extends RequestInit {
timeout?: number
}
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ''
// 运行期配置优先(容器启动时由 nginx entrypoint 注入到 /config.js 写入 window.__APP_CONFIG__
// 构建期 VITE_API_BASE_URL 作为本地 dev 的 fallback
function resolveApiBaseUrl(): string {
if (typeof window !== 'undefined') {
const runtime = (window as unknown as { __APP_CONFIG__?: { apiBaseUrl?: string } }).__APP_CONFIG__
const url = runtime?.apiBaseUrl
// 占位符未替换时(如本地直接打开 public/config.js)忽略
if (url && !(url.startsWith('__') && url.endsWith('__'))) {
return url
}
}
return import.meta.env.VITE_API_BASE_URL || ''
}
const API_BASE_URL = resolveApiBaseUrl()
async function request<T = unknown>(url: string, options: RequestOptions = {}): Promise<T> {
url = `${API_BASE_URL}${url}`