From 00cb9203cd17fcb73284340bb987c2cf9373f87c Mon Sep 17 00:00:00 2001 From: Basil Hosmer Date: Fri, 16 May 2025 16:48:31 -0400 Subject: [PATCH] fix sse endpoint path preservation --- src/client/sse.test.ts | 6 +++--- src/client/sse.ts | 8 +------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/client/sse.test.ts b/src/client/sse.test.ts index fc7a86c4..b55c7e78 100644 --- a/src/client/sse.test.ts +++ b/src/client/sse.test.ts @@ -87,7 +87,7 @@ describe("SSEClientTransport", () => { await transport.send(message); // Verify the POST request maintains the custom path - expect(lastServerRequest.url).toBe("/custom/path/messages"); + expect(lastServerRequest.url).toBe("/custom/path/sse"); }); it("handles multiple levels of custom paths", async () => { @@ -107,7 +107,7 @@ describe("SSEClientTransport", () => { await transport.send(message); // Verify the POST request maintains the full custom path - expect(lastServerRequest.url).toBe("/api/v1/custom/deep/path/messages"); + expect(lastServerRequest.url).toBe("/api/v1/custom/deep/path/sse"); }); it("maintains custom path for SSE connection", async () => { @@ -130,7 +130,7 @@ describe("SSEClientTransport", () => { }; await transport.send(message); - expect(lastServerRequest.url).toBe("/custom/path/messages"); + expect(lastServerRequest.url).toBe("/custom/path/sse"); }); it("establishes SSE connection and receives endpoint", async () => { diff --git a/src/client/sse.ts b/src/client/sse.ts index 1e481773..755f5da7 100644 --- a/src/client/sse.ts +++ b/src/client/sse.ts @@ -147,13 +147,7 @@ export class SSEClientTransport implements Transport { this._endpoint = new URL(messageEvent.data, this._url); // If the original URL had a custom path, preserve it in the endpoint URL - const originalPath = this._url.pathname; - if (originalPath && originalPath !== '/' && originalPath !== '/sse') { - // Extract the base path from the original URL (everything before the /sse suffix) - const basePath = originalPath.replace(/\/sse$/, ''); - // The endpoint should use the same base path but with /messages instead of /sse - this._endpoint.pathname = basePath + '/messages'; - } + this._endpoint.pathname = this._url.pathname; if (this._endpoint.origin !== this._url.origin) { throw new Error(