diff --git a/src/modules/v1-ws-proxy/manager.ts b/src/modules/v1-ws-proxy/manager.ts index 4011593..18bc800 100644 --- a/src/modules/v1-ws-proxy/manager.ts +++ b/src/modules/v1-ws-proxy/manager.ts @@ -134,7 +134,7 @@ export class WsProxyManager { } this.checkConnceted(); } - register(id: string, opts?: { ws: WebSocket; user: string, id?: string }) { + register(id: string, opts?: { ws: WebSocket; user: string, id?: string, isLogin: boolean }) { if (this.wssMap.has(id)) { const value = this.wssMap.get(id); if (value) { @@ -232,7 +232,7 @@ export class WsProxyManager { logger.debug('之前的连接已关闭,复用注册 ID 连接 ws', id); this.unregister(id); await new Promise(resolve => setTimeout(resolve, 100)); - const wsMessage = this.register(id, { ws: opts.ws, user: opts.user, id }); + const wsMessage = this.register(id, { ws: opts.ws, user: opts.user, id, isLogin }); wsMessage.sendConnected(); return { wsMessage, isNew: false, id: id }; } else { @@ -246,7 +246,7 @@ export class WsProxyManager { realId = id + registryId; logger.debug('未登录用户,使用临时注册 ID 连接 ws', realId); } - const wsMessage = this.register(realId, { ws: opts.ws, user: opts.user, id: realId }); + const wsMessage = this.register(realId, { ws: opts.ws, user: opts.user, id: realId, isLogin }); return { wsMessage, isNew: true, id: realId }; } } diff --git a/src/modules/v1-ws-proxy/proxy.ts b/src/modules/v1-ws-proxy/proxy.ts index 8ae89b1..8b3dcd2 100644 --- a/src/modules/v1-ws-proxy/proxy.ts +++ b/src/modules/v1-ws-proxy/proxy.ts @@ -59,9 +59,14 @@ export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opt if (!client) { if (isGet) { if (isAdmin) { - const html = createStudioAppListHtml({ user, appIds: ids, userAppKey, infoList }); + // const html = createStudioAppListHtml({ user, appIds: ids, userAppKey, infoList }); + // res.writeHead(200, { 'Content-Type': 'text/html' }); + // res.end(html); + // https://kevisual.cn/root/v1-manager/ + const html = await fetch(`${baseProxyUrl}/root/v1-manager/index.html`).then(res => res.text()); res.writeHead(200, { 'Content-Type': 'text/html' }); - res.end(html); + res.end(renderServerHtml({ user, appIds: ids, userAppKey, infoList }, html)); + return true; } else { opts?.createNotFoundPage?.('应用访问失败'); } @@ -74,9 +79,9 @@ export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opt const path = searchParams.get('path'); if (!path) { // 显示前端页面 - const html = fetch(`${baseProxyUrl}/root/router-studio/index.html`).then(res => res.text()); + const html = await fetch(`${baseProxyUrl}/root/router-studio/index.html`).then(res => res.text()); res.writeHead(200, { 'Content-Type': 'text/html' }); - res.end(await html); + res.end(html); return true; } let message: any = data; @@ -106,7 +111,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse, opts?: { // 获取所有的管理员的应用列表 const { ids, infoList } = wsProxyManager.getIdsInfo(user + '--'); if (isGet) { - const html = createStudioAppListHtml({ user, appIds: ids, userAppKey, infoList }); + const html = await fetch(`${baseProxyUrl}/root/v1-manager/index.html`).then(res => res.text()); res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(html); return; @@ -122,7 +127,6 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse, opts?: { return; } if (path === 'connected') { - client.sendConnected(); res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ code: 200, message: '应用已连接' }));