Skip to content

Commit

Permalink
feat: update path-to-regexp (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
attilaorosz authored Sep 17, 2024
1 parent 3d64ae0 commit f5e79c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
25 changes: 15 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"class-transformer": "^0.5.1",
"glob": "^11.0.0",
"path-to-regexp": "^6.2.2",
"path-to-regexp": "^8.1.0",
"reflect-metadata": "^0.2.2",
"socket.io": "^4.7.5"
},
Expand Down
18 changes: 14 additions & 4 deletions src/SocketControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class SocketControllers {
return true;
}

const nspRegexp = nsp instanceof RegExp ? nsp : pathToRegexp(nsp);
const nspRegexp = nsp instanceof RegExp ? nsp : pathToRegexp(nsp).regexp;
return nspRegexp.test(namespace.name);
});

Expand Down Expand Up @@ -145,7 +145,7 @@ export class SocketControllers {
for (const [nsp, controllers] of Object.entries(controllerNamespaceMap)) {
const namespace = controllerNamespaceRegExpMap[nsp];
this.io
.of(namespace instanceof RegExp ? namespace : pathToRegexp(namespace))
.of(namespace instanceof RegExp ? namespace : pathToRegexp(namespace).regexp)
.on('connection', (socket: Socket) => {
for (const controller of controllers) {
this.registerController(socket, controller);
Expand Down Expand Up @@ -403,8 +403,18 @@ export class SocketControllers {
namespace: string | RegExp | undefined,
parameterMetadata?: ParameterMetadata
) {
const keys: any[] = [];
const regexp = namespace instanceof RegExp ? namespace : pathToRegexp(namespace || '/', keys);
let keys: any[];
let regexp: RegExp;

if (namespace instanceof RegExp) {
regexp = namespace;
keys = [];
} else {
const pathToRegexpResult = pathToRegexp(namespace || '/');
regexp = pathToRegexpResult.regexp;
keys = pathToRegexpResult.keys;
}

const parts: any[] = regexp.exec(socket.nsp.name) || [];
const params: Record<string, string> = {};
keys.forEach((key: any, index: number) => {
Expand Down

0 comments on commit f5e79c0

Please sign in to comment.