Refactor client routes and add IP fetching functionality

- Moved client route definitions to separate files for better organization.
- Added new route to fetch client IP addresses, supporting both IPv4 and IPv6.
- Implemented system information retrieval in the client routes.
- Updated package dependencies to their latest versions.
- Adjusted call route to prevent overwriting existing routes.
This commit is contained in:
2026-02-04 13:20:12 +08:00
parent 6212194f95
commit 5d6bd4f429
21 changed files with 363 additions and 256 deletions

View File

@@ -1,5 +1,5 @@
import { App } from '@kevisual/router'
import { App, ListenProcessResponse } from '@kevisual/router'
import { WebSocket } from 'ws'
import { ReconnectingWebSocket, handleCallApp } from '@kevisual/router/ws'
import net from 'net';
@@ -23,7 +23,7 @@ app.createRouteList();
await new Promise((resolve) => setTimeout(resolve, 1000));
// 创建支持断开重连的 WebSocket 客户端
const ws = new ReconnectingWebSocket('ws://localhost:51516/livecode/ws?id=test-live-app', {
const ws = new ReconnectingWebSocket('ws://localhost:51515/livecode/ws?id=test-live-app', {
maxRetries: Infinity, // 无限重试
retryDelay: 1000, // 初始重试延迟 1 秒
maxDelay: 30000, // 最大延迟 30 秒
@@ -33,7 +33,7 @@ ws.onMessage(async (message) => {
console.log('收到消息:', message);
if (message.type === 'router' && message.id) {
console.log('收到路由响应:', message);
const data = message?.data;
const data = message?.data as ListenProcessResponse;
if (!data) {
ws.send({
type: 'router',
@@ -42,7 +42,17 @@ ws.onMessage(async (message) => {
});
return;
}
const res = await app.run(message.data);
const msg = data.message;
if (!msg) {
ws.send({
type: 'router',
id: message.id,
data: { code: 500, message: 'No {message} received' }
});
return;
}
const context = data.context || {};
const res = await app.run(msg, context);
console.log('路由处理结果:', res);
ws.send({
type: 'router',