diff --git a/rest/nodejs/src/api/discovery.ts b/rest/nodejs/src/api/discovery.ts index c179166..98559e6 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 11dfbe1..bdb2303 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" + ); +});