feat: implement initial backend API server and frontend configuration context for the application.
This commit is contained in:
@@ -55,7 +55,7 @@ export function ConfigProvider({ children }: { children: ReactNode }) {
|
||||
refreshConfig()
|
||||
}, [refreshConfig])
|
||||
|
||||
// Update S2A client when config changes
|
||||
// Update S2A client when config changes and auto-test connection
|
||||
useEffect(() => {
|
||||
if (config.s2a.apiBase && config.s2a.adminKey) {
|
||||
const client = new S2AClient({
|
||||
@@ -63,6 +63,16 @@ export function ConfigProvider({ children }: { children: ReactNode }) {
|
||||
apiKey: config.s2a.adminKey,
|
||||
})
|
||||
setS2aClient(client)
|
||||
|
||||
// 自动测试连接
|
||||
fetch('/api/s2a/test')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
setIsConnected(data.code === 0)
|
||||
})
|
||||
.catch(() => {
|
||||
setIsConnected(false)
|
||||
})
|
||||
} else {
|
||||
setS2aClient(null)
|
||||
setIsConnected(false)
|
||||
|
||||
Reference in New Issue
Block a user