Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest/nodejs/src/api/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
Expand Down
19 changes: 18 additions & 1 deletion rest/nodejs/test/discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [
Expand All @@ -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"
);
});
Loading