fix production attachment file origin
This commit is contained in:
@@ -27,6 +27,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker build \
|
docker build \
|
||||||
--build-arg TINODE_API_KEY="${{ secrets.TINODE_API_KEY }}" \
|
--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 }} .
|
-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 }}
|
docker push git.118im.com/im_team/im-webapp:${{ steps.vars.outputs.tag }}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ COPY web/. .
|
|||||||
ARG TINODE_API_KEY=
|
ARG TINODE_API_KEY=
|
||||||
ENV VITE_TINODE_API_KEY=$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
|
RUN npm run build
|
||||||
|
|
||||||
# ---- Stage 2: serve with nginx ----
|
# ---- Stage 2: serve with nginx ----
|
||||||
|
|||||||
@@ -26,9 +26,14 @@ npm run build
|
|||||||
根目录 `Dockerfile` 只复制并构建 `web/`:
|
根目录 `Dockerfile` 只复制并构建 `web/`:
|
||||||
|
|
||||||
```bash
|
```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)` 工作流手动发布。
|
测试集群通过 Gitea Actions 的 `Deploy im-webapp (k3s test cluster)` 工作流手动发布。
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { useSessionStore } from '@/stores/session';
|
|||||||
|
|
||||||
const DEFAULT_API_BASE = '/v1/im';
|
const DEFAULT_API_BASE = '/v1/im';
|
||||||
const DEFAULT_FILE_BASE = '/v0/file';
|
const DEFAULT_FILE_BASE = '/v0/file';
|
||||||
|
const CONFIGURED_FILE_BASE = import.meta.env.VITE_TINODE_FILE_BASE?.trim();
|
||||||
|
|
||||||
export class ImApiError extends Error {
|
export class ImApiError extends Error {
|
||||||
reason?: string;
|
reason?: string;
|
||||||
@@ -123,7 +124,11 @@ export function apiBase(): string {
|
|||||||
|
|
||||||
export function fileBase(): string {
|
export function fileBase(): string {
|
||||||
const endpoints = useSessionStore.getState().tenant?.endpoints;
|
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 {
|
export function currentTenantCode(): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user