Skip to content

Commit

Permalink
feat: ignore the query string when serving client JavaScript (#4024)
Browse files Browse the repository at this point in the history
Related: #4023
  • Loading branch information
TimWolla committed Aug 30, 2021
1 parent 310f855 commit 24fee27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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";

Expand Down
4 changes: 4 additions & 0 deletions test/socket.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down

0 comments on commit 24fee27

Please sign in to comment.