Commit c1dd9e0c authored by nanahira's avatar nanahira

support regex ws path match

parent abf80b39
......@@ -494,6 +494,14 @@ export class AppModule {}
## 更新历史
### 1.4.2
* `KoishiWsAdapter`: 支持正则表达式路径。
### 1.4
* 适配最新的 Koishi 版本的 Websocket 变动。 **使用涉及 Websocket 的 Koishi 插件需要使用附带的 `KoishiWsAdapter`。**
### 1.3.3
* 移除了 `http-proxy-middleware`
......
......@@ -7,7 +7,17 @@ export class KoishiWsAdapter extends WsAdapter {
super(appOrHttpServer);
}
override ensureHttpServerExists(
protected override addWsServerToRegistry<
T extends Record<'path', string> = any,
>(wsServer: T, port: number, path: string) {
super.addWsServerToRegistry(wsServer, port, path);
const { options } = wsServer as any;
if (options && typeof options === 'object') {
options.path = undefined;
}
}
protected override ensureHttpServerExists(
port: number,
httpServer = http.createServer(),
) {
......@@ -24,7 +34,7 @@ export class KoishiWsAdapter extends WsAdapter {
let isRequestDelegated = false;
let fallbackWsServer: any;
for (const wsServer of wsServersCollection) {
if (pathname === wsServer.path) {
if (pathname?.match(wsServer.path)) {
wsServer.handleUpgrade(request, socket, head, (ws: unknown) => {
wsServer.emit('connection', ws, request);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment