Przeglądaj źródła

fi: TypeError [ERR_INVALID_URL] when parsing query paramters

Relative URLs require a base url parameter
Jonas Gloning 1 rok temu
rodzic
commit
4ca09b4963
1 zmienionych plików z 3 dodań i 4 usunięć
  1. 3 4
      src/services/webSocketServer/index.ts

+ 3 - 4
src/services/webSocketServer/index.ts

@@ -70,10 +70,9 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
 			this._onSocketError(error);
 		});
 
-		const { searchParams } = new URL(req.url ?? "");
-		const id = searchParams.get("id");
-		const token = searchParams.get("token");
-		const key = searchParams.get("key");
+		// We are only interested in the query, the base url is therefore not relevant
+		const { searchParams } = new URL(req.url ?? "", "https://peerjs");
+		const { id, token, key } = Object.fromEntries(searchParams.entries());
 
 		if (!id || !token || !key) {
 			this._sendErrorAndClose(socket, Errors.INVALID_WS_PARAMETERS);