Update Mihomo configuration and documentation for clarity
Publish telemt-api gateway Docker image / test (push) Successful in 28s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m10s

- Revised comments in `config.example.yaml` to enhance understanding of Mihomo integration, including environment variable usage and Docker Compose setup.
- Updated `docker-compose.yml` comments to clarify the relationship between the gateway and Mihomo service.
- Enhanced `GATEWAY_RUN.md` to provide clearer instructions on configuring Mihomo parameters and their usage in the gateway.
This commit is contained in:
Denozordec
2026-03-31 00:54:41 +07:00
parent a24fc90b39
commit ed785cb8f3
6 changed files with 46 additions and 63 deletions
+15 -4
View File
@@ -28,9 +28,20 @@ export function mihomoWsUrl(alias: string, path: string): string {
return `${wsBase}/api/${encodeURIComponent(alias)}/mihomo/${p}`;
}
async function parseMihomoBody(res: Response): Promise<unknown> {
const text = await res.text();
if (!text) return null;
try {
return JSON.parse(text);
} catch {
const snip = text.length > 200 ? `${text.slice(0, 200)}` : text;
throw new ApiError(`Ответ не JSON (HTTP ${res.status}): ${snip}`, res.status, text);
}
}
export async function fetchMihomoMeta(alias: string): Promise<MihomoMetaResponse> {
const res = await fetch(mihomoUrl(alias, 'meta'));
const body = (await parseJson(res)) as Record<string, unknown> | null;
const body = (await parseMihomoBody(res)) as Record<string, unknown> | null;
if (res.status === 404) {
throw new ApiError('Mihomo не настроен для этой ноды', 404, body);
}
@@ -45,7 +56,7 @@ export async function fetchMihomoMeta(alias: string): Promise<MihomoMetaResponse
export async function fetchMihomoJson<T>(alias: string, path: string): Promise<T> {
const res = await fetch(mihomoUrl(alias, path));
const body = await parseJson(res);
const body = await parseMihomoBody(res);
if (res.status === 404) {
throw new ApiError('Mihomo не настроен для этой ноды', 404, body);
}
@@ -62,11 +73,11 @@ export async function mihomoPut(alias: string, path: string, jsonBody: unknown):
body: JSON.stringify(jsonBody)
});
if (res.status === 404) {
const body = await parseJson(res);
const body = await parseMihomoBody(res);
throw new ApiError('Mihomo не настроен для этой ноды', 404, body);
}
if (!res.ok) {
const body = await parseJson(res);
const body = await parseMihomoBody(res);
throw new ApiError(`Mihomo PUT HTTP ${res.status}`, res.status, body);
}
}