-
Notifications
You must be signed in to change notification settings - Fork 1
Prioritize /api/v1/discovery over .well-known/objectstack per protocol #1151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -253,12 +253,26 @@ export class ObjectStackClient { | |||||||||||||||||
| */ | ||||||||||||||||||
| async connect() { | ||||||||||||||||||
| this.logger.debug('Connecting to ObjectStack server', { baseUrl: this.baseUrl }); | ||||||||||||||||||
|
|
||||||||||||||||||
| try { | ||||||||||||||||||
| let data: DiscoveryResult | undefined; | ||||||||||||||||||
|
|
||||||||||||||||||
| // 1. Try Standard Discovery (.well-known) | ||||||||||||||||||
| // 1. Try Protocol-standard Discovery Path /api/v1/discovery (primary) | ||||||||||||||||||
| try { | ||||||||||||||||||
| const discoveryUrl = `${this.baseUrl}/api/v1/discovery`; | ||||||||||||||||||
| this.logger.debug('Probing protocol-standard discovery endpoint', { url: discoveryUrl }); | ||||||||||||||||||
| const res = await this.fetchImpl(discoveryUrl); | ||||||||||||||||||
| if (res.ok) { | ||||||||||||||||||
| const body = await res.json(); | ||||||||||||||||||
| data = body.data || body; | ||||||||||||||||||
| this.logger.debug('Discovered via /api/v1/discovery'); | ||||||||||||||||||
|
||||||||||||||||||
| this.logger.debug('Discovered via /api/v1/discovery'); | |
| this.logger.debug('Discovered via /api/v1/discovery'); | |
| } else { | |
| this.logger.debug('Protocol-standard discovery endpoint returned non-success status', { | |
| url: discoveryUrl, | |
| status: res.status, | |
| statusText: res.statusText | |
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,15 +13,15 @@ import { ObjectStackClient } from '../../src/index'; | |
| const TEST_SERVER_URL = process.env.TEST_SERVER_URL || 'http://localhost:3000'; | ||
|
|
||
| describe('Discovery & Connection', () => { | ||
| describe('TC-DISC-001: Standard Discovery via .well-known', () => { | ||
| test('should discover API from .well-known/objectstack', async () => { | ||
| const client = new ObjectStackClient({ | ||
| describe('TC-DISC-001: Protocol-standard Discovery via /api/v1/discovery', () => { | ||
| test('should discover API from /api/v1/discovery', async () => { | ||
| const client = new ObjectStackClient({ | ||
| baseUrl: TEST_SERVER_URL, | ||
| debug: true | ||
| }); | ||
|
|
||
| const discovery = await client.connect(); | ||
|
Comment on lines
+16
to
23
|
||
|
|
||
| expect(discovery.version).toBeDefined(); | ||
| expect(discovery.apiName).toBeDefined(); | ||
| expect(discovery.routes).toBeDefined(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discoveryUrlis built via string concatenation withbaseUrl(${this.baseUrl}/api/v1/discovery). IfbaseUrlcontains a path segment (e.g.https://host/some/prefix), this will probe.../some/prefix/api/v1/discovery, which is inconsistent with the.well-knownlogic (which correctly usesnew URL(this.baseUrl).origin). Consider constructing the protocol-standard discovery URL using the parsed origin as well (and falling back to a root-relative/api/v1/discoverywhenbaseUrlisn’t absolute).