Skip to content

Commit f9001c1

Browse files
committed
feat(api): update discovery endpoints to return data objects
1 parent b1dc6dc commit f9001c1

6 files changed

Lines changed: 26 additions & 10 deletions

File tree

content/docs/objectos/http-protocol.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Host: api.acme.com
3131

3232
**Alternative endpoint:**
3333
```http
34-
GET /api/v1/discovery HTTP/1.1
34+
GET /api/v1 HTTP/1.1
3535
```
3636

3737
**Response:**

packages/adapters/hono/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function createHonoApp(options: ObjectStackHonoOptions) {
4444

4545
// --- 0. Discovery Endpoint ---
4646
app.get(prefix, (c) => {
47-
return c.json(dispatcher.getDiscoveryInfo(prefix));
47+
return c.json({ data: dispatcher.getDiscoveryInfo(prefix) });
4848
});
4949

5050
// --- 1. Auth ---

packages/adapters/nestjs/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class ObjectStackController {
8787
// --- Discovery Endpoint ---
8888
@Get()
8989
discovery() {
90-
return this.service.dispatcher.getDiscoveryInfo('/api');
90+
return { data: this.service.dispatcher.getDiscoveryInfo('/api') };
9191
}
9292

9393
@Post('graphql')

packages/adapters/nextjs/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function createRouteHandler(options: NextAdapterOptions) {
5151

5252
// --- 0. Discovery Endpoint ---
5353
if (segments.length === 0 && method === 'GET') {
54-
return NextResponse.json(dispatcher.getDiscoveryInfo(options.prefix || '/api'));
54+
return NextResponse.json({ data: dispatcher.getDiscoveryInfo(options.prefix || '/api') });
5555
}
5656

5757
try {

packages/plugins/plugin-hono-server/src/hono-plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from '@objectstack/spec/api';
88
import { HonoHttpServer } from './adapter';
99
import { createHonoApp } from '@objectstack/hono';
10+
import { HttpDispatcher } from '@objectstack/runtime';
1011
import { serveStatic } from '@hono/node-server/serve-static';
1112
import * as fs from 'fs';
1213
import * as path from 'path';
@@ -123,8 +124,9 @@ export class HonoServerPlugin implements Plugin {
123124

124125
// Register Standard Discovery Endpoint
125126
const rawApp = this.server.getRawApp();
127+
const dispatcher = new HttpDispatcher(kernel);
126128
rawApp.get('/.well-known/objectstack', (c) => {
127-
return c.redirect(apiPath);
129+
return c.json({ data: dispatcher.getDiscoveryInfo(apiPath) });
128130
});
129131
ctx.logger.debug('Registered standard discovery endpoint', { path: '/.well-known/objectstack', target: apiPath });
130132

packages/plugins/plugin-msw/src/msw-plugin.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,26 @@ export class MSWPlugin implements Plugin {
203203
// Discovery Endpoint
204204
this.handlers.push(
205205
http.get('*/.well-known/objectstack', () => {
206-
return new HttpResponse(null, {
207-
status: 302,
208-
headers: {
209-
Location: baseUrl
206+
if (this.dispatcher) {
207+
return HttpResponse.json({
208+
data: this.dispatcher.getDiscoveryInfo(baseUrl)
209+
});
210+
}
211+
return HttpResponse.json({
212+
data: {
213+
version: 'v1',
214+
apiName: 'ObjectStack API',
215+
url: baseUrl,
216+
capabilities: {
217+
graphql: false,
218+
search: false,
219+
websockets: false,
220+
files: false,
221+
analytics: false,
222+
hub: false
223+
}
210224
}
211-
})
225+
});
212226
})
213227
);
214228

0 commit comments

Comments
 (0)