Skip to content

Commit 0b04280

Browse files
authored
Revert "fix sse endpoint path preservation"
1 parent 6be4c60 commit 0b04280

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/client/sse.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("SSEClientTransport", () => {
8787
await transport.send(message);
8888

8989
// Verify the POST request maintains the custom path
90-
expect(lastServerRequest.url).toBe("/custom/path/sse");
90+
expect(lastServerRequest.url).toBe("/custom/path/messages");
9191
});
9292

9393
it("handles multiple levels of custom paths", async () => {
@@ -107,7 +107,7 @@ describe("SSEClientTransport", () => {
107107
await transport.send(message);
108108

109109
// Verify the POST request maintains the full custom path
110-
expect(lastServerRequest.url).toBe("/api/v1/custom/deep/path/sse");
110+
expect(lastServerRequest.url).toBe("/api/v1/custom/deep/path/messages");
111111
});
112112

113113
it("maintains custom path for SSE connection", async () => {
@@ -130,7 +130,7 @@ describe("SSEClientTransport", () => {
130130
};
131131

132132
await transport.send(message);
133-
expect(lastServerRequest.url).toBe("/custom/path/sse");
133+
expect(lastServerRequest.url).toBe("/custom/path/messages");
134134
});
135135

136136
it("establishes SSE connection and receives endpoint", async () => {

src/client/sse.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ export class SSEClientTransport implements Transport {
147147
this._endpoint = new URL(messageEvent.data, this._url);
148148

149149
// If the original URL had a custom path, preserve it in the endpoint URL
150-
this._endpoint.pathname = this._url.pathname;
150+
const originalPath = this._url.pathname;
151+
if (originalPath && originalPath !== '/' && originalPath !== '/sse') {
152+
// Extract the base path from the original URL (everything before the /sse suffix)
153+
const basePath = originalPath.replace(/\/sse$/, '');
154+
// The endpoint should use the same base path but with /messages instead of /sse
155+
this._endpoint.pathname = basePath + '/messages';
156+
}
151157

152158
if (this._endpoint.origin !== this._url.origin) {
153159
throw new Error(

0 commit comments

Comments
 (0)