fix production attachment file origin

This commit is contained in:
richjohnrambo
2026-10-14 15:22:46 +08:00
parent c1338985d4
commit 8a26a4ccf9
4 changed files with 18 additions and 2 deletions
+1
View File
@@ -27,6 +27,7 @@ jobs:
run: |
docker build \
--build-arg TINODE_API_KEY="${{ secrets.TINODE_API_KEY }}" \
--build-arg TINODE_FILE_BASE="https://api.118im.com/v0/file" \
-t git.118im.com/im_team/im-webapp:${{ steps.vars.outputs.tag }} .
docker push git.118im.com/im_team/im-webapp:${{ steps.vars.outputs.tag }}
+5
View File
@@ -14,6 +14,11 @@ COPY web/. .
ARG TINODE_API_KEY=
ENV VITE_TINODE_API_KEY=$TINODE_API_KEY
# File downloads must use the canonical IM API origin. The web origin has its own independently
# deployed path router and may otherwise send /v0/file requests to an older IM server.
ARG TINODE_FILE_BASE=https://api.118im.com/v0/file
ENV VITE_TINODE_FILE_BASE=$TINODE_FILE_BASE
RUN npm run build
# ---- Stage 2: serve with nginx ----
+6 -1
View File
@@ -26,9 +26,14 @@ npm run build
根目录 `Dockerfile` 只复制并构建 `web/`:
```bash
docker build --build-arg TINODE_API_KEY="<部署密钥>" -t im-webapp .
docker build \
--build-arg TINODE_API_KEY="<部署密钥>" \
--build-arg TINODE_FILE_BASE="https://api.118im.com/v0/file" \
-t im-webapp .
```
生产环境通过 `TINODE_FILE_BASE` 固定附件下载入口;本地开发不设置该变量时,继续使用租户解析结果和 Vite 代理。
测试集群通过 Gitea Actions 的 `Deploy im-webapp (k3s test cluster)` 工作流手动发布。
## 目录
+6 -1
View File
@@ -12,6 +12,7 @@ import { useSessionStore } from '@/stores/session';
const DEFAULT_API_BASE = '/v1/im';
const DEFAULT_FILE_BASE = '/v0/file';
const CONFIGURED_FILE_BASE = import.meta.env.VITE_TINODE_FILE_BASE?.trim();
export class ImApiError extends Error {
reason?: string;
@@ -123,7 +124,11 @@ export function apiBase(): string {
export function fileBase(): string {
const endpoints = useSessionStore.getState().tenant?.endpoints;
return (endpoints?.file || DEFAULT_FILE_BASE).replace(/\/$/, '');
// Production may expose the web UI and the IM API through different deployments. Prefer the
// build-time canonical file origin so a tenant context previously resolved through the web host
// cannot keep routing attachments to that host's stale /v0/file proxy. Local development leaves
// this unset and continues to use the resolved relative endpoint through Vite's proxy.
return (CONFIGURED_FILE_BASE || endpoints?.file || DEFAULT_FILE_BASE).replace(/\/$/, '');
}
export function currentTenantCode(): string {