From e8a0d0e9005b4c2513f96e1ae2dceb30dff09259 Mon Sep 17 00:00:00 2001 From: "tyrion.lh" Date: Wed, 29 Jul 2026 18:28:41 +0800 Subject: [PATCH 1/2] fix(nodejs): derive discovery endpoint from request origin --- rest/nodejs/src/api/discovery.ts | 2 +- rest/nodejs/test/discovery.test.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/rest/nodejs/src/api/discovery.ts b/rest/nodejs/src/api/discovery.ts index c179166b..98559e63 100644 --- a/rest/nodejs/src/api/discovery.ts +++ b/rest/nodejs/src/api/discovery.ts @@ -110,7 +110,7 @@ export class DiscoveryService { spec: `https://ucp.dev/${this.ucpVersion}/specification/shopping`, transport: "rest", schema: `https://ucp.dev/${this.ucpVersion}/services/shopping/openapi.json`, - endpoint: "http://localhost:3000", + endpoint: new URL(c.req.url).origin, }, ], }, diff --git a/rest/nodejs/test/discovery.test.ts b/rest/nodejs/test/discovery.test.ts index 11dfbe15..f9687dd3 100644 --- a/rest/nodejs/test/discovery.test.ts +++ b/rest/nodejs/test/discovery.test.ts @@ -26,7 +26,7 @@ test("merchant profile uses schema-compliant discovery registries", async () => assert.ok(Array.isArray(shoppingServices)); assert.equal(shoppingServices.length, 1); assert.equal(shoppingServices[0]?.transport, "rest"); - assert.equal(shoppingServices[0]?.endpoint, "http://localhost:3000"); + assert.equal(shoppingServices[0]?.endpoint, "http://localhost"); assert.equal(Array.isArray(body.ucp.capabilities), false); assert.deepEqual(Object.keys(body.ucp.capabilities).sort(), [ @@ -46,3 +46,20 @@ test("merchant profile uses schema-compliant discovery registries", async () => assert.equal(declarations[0]?.version, discoveryService.ucpVersion); } }); + +test("merchant profile derives the REST endpoint from the request origin", async () => { + const app = new Hono(); + const discoveryService = new DiscoveryService(); + app.get("/.well-known/ucp", discoveryService.getMerchantProfile); + + const response = await app.request( + "https://merchant.example:8443/.well-known/ucp", + ); + const body = (await response.json()) as DiscoveryResponse; + + assert.equal(response.status, 200); + assert.equal( + body.ucp.services["dev.ucp.shopping"]?.[0]?.endpoint, + "https://merchant.example:8443", + ); +}); From dd8953af9b804bccca8562774e25a47b3f2ac701 Mon Sep 17 00:00:00 2001 From: damaz91 Date: Wed, 29 Jul 2026 14:03:25 +0000 Subject: [PATCH 2/2] style(nodejs): remove trailing commas in discovery test --- rest/nodejs/test/discovery.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest/nodejs/test/discovery.test.ts b/rest/nodejs/test/discovery.test.ts index f9687dd3..bdb23039 100644 --- a/rest/nodejs/test/discovery.test.ts +++ b/rest/nodejs/test/discovery.test.ts @@ -53,13 +53,13 @@ test("merchant profile derives the REST endpoint from the request origin", async app.get("/.well-known/ucp", discoveryService.getMerchantProfile); const response = await app.request( - "https://merchant.example:8443/.well-known/ucp", + "https://merchant.example:8443/.well-known/ucp" ); const body = (await response.json()) as DiscoveryResponse; assert.equal(response.status, 200); assert.equal( body.ucp.services["dev.ucp.shopping"]?.[0]?.endpoint, - "https://merchant.example:8443", + "https://merchant.example:8443" ); });