@nextclaw/ui 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/assets/{index-BIesvTqn.js → index-BivRvIey.js} +45 -45
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/api/client.ts +17 -1
- package/src/hooks/useWebSocket.ts +28 -1
package/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>nextclaw - 系统配置</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BivRvIey.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-iSLahgqA.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
package/package.json
CHANGED
package/src/api/client.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import type { ApiResponse } from './types';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const DEFAULT_API_BASE = 'http://127.0.0.1:18791';
|
|
4
|
+
const API_BASE = (() => {
|
|
5
|
+
const envBase = import.meta.env.VITE_API_BASE?.trim();
|
|
6
|
+
if (envBase) {
|
|
7
|
+
return envBase.replace(/\/$/, '');
|
|
8
|
+
}
|
|
9
|
+
if (typeof window !== 'undefined' && window.location?.origin) {
|
|
10
|
+
return window.location.origin;
|
|
11
|
+
}
|
|
12
|
+
return DEFAULT_API_BASE;
|
|
13
|
+
})();
|
|
14
|
+
|
|
15
|
+
if (import.meta.env.DEV && !import.meta.env.VITE_API_BASE) {
|
|
16
|
+
console.warn('VITE_API_BASE is not set; falling back to window origin.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { API_BASE };
|
|
4
20
|
|
|
5
21
|
async function apiRequest<T>(
|
|
6
22
|
endpoint: string,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { ConfigWebSocket } from '@/api/websocket';
|
|
3
|
+
import { API_BASE } from '@/api/client';
|
|
3
4
|
import { useUiStore } from '@/stores/ui.store';
|
|
4
5
|
import type { QueryClient } from '@tanstack/react-query';
|
|
5
6
|
|
|
@@ -8,7 +9,33 @@ export function useWebSocket(queryClient?: QueryClient) {
|
|
|
8
9
|
const { setConnectionStatus } = useUiStore();
|
|
9
10
|
|
|
10
11
|
useEffect(() => {
|
|
11
|
-
const wsUrl =
|
|
12
|
+
const wsUrl = (() => {
|
|
13
|
+
const base = API_BASE?.replace(/\/$/, '');
|
|
14
|
+
if (!base) {
|
|
15
|
+
return 'ws://127.0.0.1:18791/ws';
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const resolved = new URL(base, window.location.origin);
|
|
19
|
+
const protocol =
|
|
20
|
+
resolved.protocol === 'https:'
|
|
21
|
+
? 'wss:'
|
|
22
|
+
: resolved.protocol === 'http:'
|
|
23
|
+
? 'ws:'
|
|
24
|
+
: resolved.protocol;
|
|
25
|
+
return `${protocol}//${resolved.host}/ws`;
|
|
26
|
+
} catch {
|
|
27
|
+
if (base.startsWith('wss://') || base.startsWith('ws://')) {
|
|
28
|
+
return `${base}/ws`;
|
|
29
|
+
}
|
|
30
|
+
if (base.startsWith('https://')) {
|
|
31
|
+
return `${base.replace(/^https:/, 'wss:')}/ws`;
|
|
32
|
+
}
|
|
33
|
+
if (base.startsWith('http://')) {
|
|
34
|
+
return `${base.replace(/^http:/, 'ws:')}/ws`;
|
|
35
|
+
}
|
|
36
|
+
return `${base}/ws`;
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
12
39
|
const client = new ConfigWebSocket(wsUrl);
|
|
13
40
|
|
|
14
41
|
client.on('connection.open', () => {
|