feat: update WebSocket connection and add system version sending functionality
- Changed WebSocket connection URL to localhost for testing. - Added a function to send system version to the server upon connection and after a delay. - Improved logging for received messages. chore: update package dependencies - Bump versions for several dependencies including @kevisual/query, lucide-react, vue, and others. - Update package manager version to pnpm@10.26.1. fix: adjust app initialization to use sessionStorage - Modified the app initialization to use a custom sessionStorage implementation backed by an LRU cache. feat: implement sessionStorage with LRU cache - Added a new module for sessionStorage that utilizes LRUCache for efficient caching.
This commit is contained in:
@@ -2,6 +2,7 @@ import http from 'node:http';
|
||||
import https from 'node:https';
|
||||
import { rewriteCookieDomain } from '../https/cookie-rewrite.ts';
|
||||
import { ProxyInfo } from './proxy.ts';
|
||||
import { pipeStream } from './pipe.ts';
|
||||
export const defaultApiProxy = [
|
||||
{
|
||||
path: '/api/router',
|
||||
@@ -109,5 +110,6 @@ export const httpProxy = (req: http.IncomingMessage, res: http.ServerResponse, p
|
||||
});
|
||||
// 处理 POST 请求的请求体(传递数据到目标服务器),end:true 表示当请求体结束时,关闭请求
|
||||
req.pipe(proxyReq, { end: true });
|
||||
return;
|
||||
};
|
||||
// @ts-ignore
|
||||
// pipeStream(proxyReq, res);
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './proxy.ts';
|
||||
export * from './file-proxy.ts';
|
||||
export { default as send } from 'send';
|
||||
export * from './http-proxy.ts';
|
||||
export * from './ws-proxy.ts';
|
||||
export * from './http-proxy.ts';
|
||||
19
assistant/src/module/assistant/proxy/pipe.ts
Normal file
19
assistant/src/module/assistant/proxy/pipe.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as http from 'http';
|
||||
import * as fs from 'fs';
|
||||
import { isBun } from './utils.ts';
|
||||
|
||||
export const pipeFileStream = (filePath: string, res: http.ServerResponse) => {
|
||||
const readStream = fs.createReadStream(filePath);
|
||||
if (isBun) {
|
||||
res.pipe(readStream as any);
|
||||
} else {
|
||||
readStream.pipe(res, { end: true });
|
||||
}
|
||||
}
|
||||
export const pipeStream = (readStream: fs.ReadStream, res: http.ServerResponse) => {
|
||||
if (isBun) {
|
||||
res.pipe(readStream as any);
|
||||
} else {
|
||||
readStream.pipe(res, { end: true });
|
||||
}
|
||||
}
|
||||
6
assistant/src/module/assistant/proxy/utils.ts
Normal file
6
assistant/src/module/assistant/proxy/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const isBun = typeof Bun !== 'undefined' && Bun?.version != null;
|
||||
|
||||
export const isNode = typeof process !== 'undefined' && process?.versions != null && process.versions?.node != null;
|
||||
|
||||
// @ts-ignore
|
||||
export const isDeno = typeof Deno !== 'undefined' && Deno?.version != null && Deno?.version?.deno != null;
|
||||
@@ -4,6 +4,7 @@ import type { Http2Server } from 'node:http2';
|
||||
import { WebSocket } from 'ws';
|
||||
import { ProxyInfo } from './proxy.ts';
|
||||
import { WebSocketServer } from 'ws';
|
||||
import { isBun, isNode } from './utils.ts';
|
||||
|
||||
export const wss = new WebSocketServer({
|
||||
noServer: true,
|
||||
@@ -97,7 +98,13 @@ export const wsProxy = (server: HttpServer | HttpsServer | Http2Server, config:
|
||||
await wssApp.handleConnection(ws, req);
|
||||
});
|
||||
// 处理升级请求
|
||||
server.on('upgrade', (request, socket, head) => {
|
||||
wssApp.upgrade(request, socket, head);
|
||||
});
|
||||
if (!isBun) {
|
||||
server.on('upgrade', (request, socket, head) => {
|
||||
wssApp.upgrade(request, socket, head);
|
||||
});
|
||||
} else if (isBun) {
|
||||
// @ts-ignore
|
||||
console.warn('Bun WebSocket proxy is not implemented yet.');
|
||||
console.log('server', server)
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user