diff --git a/lib/index.ts b/lib/index.ts index c7b04d03cd..165ae65c41 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -334,7 +334,7 @@ export class Server< this.clientPathRegex = new RegExp( "^" + escapedPath + - "/socket\\.io(\\.min|\\.msgpack\\.min)?\\.js(\\.map)?$" + "/socket\\.io(\\.min|\\.msgpack\\.min)?\\.js(\\.map)?(?:\\?|$)" ); return this; } @@ -487,7 +487,7 @@ export class Server< * @private */ private serve(req: http.IncomingMessage, res: http.ServerResponse): void { - const filename = req.url!.replace(this._path, ""); + const filename = req.url!.replace(this._path, "").replace(/\?.*$/, ""); const isMap = dotMapRegex.test(filename); const type = isMap ? "map" : "source"; diff --git a/test/socket.io.ts b/test/socket.io.ts index 7860405a88..630fc296f5 100644 --- a/test/socket.io.ts +++ b/test/socket.io.ts @@ -83,6 +83,10 @@ describe("socket.io", () => { }; it("should serve client", testSource("socket.io.js")); + it( + "should serve client with query string", + testSource("socket.io.js?buster=" + Date.now()) + ); it("should serve source map", testSourceMap("socket.io.js.map")); it("should serve client (min)", testSource("socket.io.min.js"));