Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ Admin 地址为 `http://localhost:3000/admin/`;另开终端运行 `npm run cha
| `VITE_ENTRY` | `admin.html` | `chat.html` | HTML 入口 |
| `VITE_API_TARGET` | 未设置 | 未设置 | 覆盖开发代理的后端地址 |

当前未设置 `VITE_API_TARGET` 时,使用 `vite.config.ts` 中的 `defaultBackendTarget`,
值为 `https://mkv3-ee.fit2cloud.cn/`。连接本地后端时,在 `env/.env.local` 中配置:
未设置 `VITE_API_TARGET` 时,开发代理使用 `vite.config.ts` 中的 `defaultBackendTarget`
(`http://127.0.0.1:8080/`)。需要连接其他后端时,在 Git 已忽略的本地覆盖文件中设置,
例如在 `env/.env.local` 中配置本地端口:

```dotenv
VITE_API_TARGET=http://127.0.0.1:8080
VITE_API_TARGET=http://127.0.0.1:8081
```

开发代理覆盖 `/admin/api`、`/chat/api`、`/doc`、`/schema`、`/static` 和当前应用基础路径下的
Expand Down
2 changes: 1 addition & 1 deletion ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { defineConfig, loadEnv } from 'vite'
import type { Plugin, ProxyOptions, ViteDevServer } from 'vite'

const envDir = './env'
const defaultBackendTarget = 'https://mkv3-ee.fit2cloud.cn/'
const defaultBackendTarget = 'http://127.0.0.1:8080/'
const projectRoot = fileURLToPath(new URL('.', import.meta.url))

const renameHtmlPlugin = (outDir: string, entry: string) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff shows a single change: the default backend target for the Vite dev proxy was changed from https://mkv3-ee.fit2cloud.cn/ to http://[IP]:8080/.

Irregularities / issues:

  1. [IP] is a placeholder, not a valid host. As written, http://[IP]:8080/ will fail if left unresolved. Note that [IP] in brackets looks like an IPv6 literal, but IP is not valid hex, so URL parsing may throw or the proxy will simply fail to connect. Either substitute a real address or use a clearly-invalid-but-unambiguous placeholder (e.g., http://localhost:8080/).

  2. Loss of TLS. The original used https://; the new default uses plain http://. If the backend still serves HTTPS, this will break (connection refused / protocol error). Confirm the backend actually speaks HTTP on 8080.

  3. Committed placeholder in source code. Hardcoding [IP] in a tracked config file risks it being accidentally shipped or confusing other developers. Prefer driving the target from an environment variable (loadEnv is already imported) rather than editing the source per developer/machine.

  4. Trailing slash. The original had a trailing /; http://[IP]:8080/ also does — just make sure the proxy rewrite logic expects (or normalizes) the trailing slash consistently, since path joining can double slashes otherwise.

  5. Port change implication. Moving to port 8080 suggests a different service than the original production host. Ensure any cookie/CORS/origin expectations (cookies domain, redirect URLs) match, as dev-proxy behavior changes when host/port/scheme change.

Optimization suggestions:

  • Replace the hardcoded constant with an env-driven value, e.g.:
    const defaultBackendTarget = process.env.VITE_BACKEND_TARGET ?? 'http://localhost:8080/'
    and document it in .env.example.
  • Validate the target at startup (e.g., new URL(defaultBackendTarget)) to surface misconfiguration early.
  • If IP-based access is needed, use the fully qualified address (http://192.168.x.x:8080/) and avoid bracket syntax unless truly using IPv6.
  • Add a brief comment explaining why the default differs from production, to prevent future confusion.

No structural problems with the surrounding code are visible from this fragment itself — the concerns above all stem from the changed value.

Expand Down
Loading