Skip to content

Commit afc4f87

Browse files
committed
feat: add UI request handling to HttpDispatcher
1 parent 5dc89f4 commit afc4f87

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

packages/runtime/src/http-dispatcher.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class HttpDispatcher {
6565
data: `${prefix}/data`,
6666
metadata: `${prefix}/meta`,
6767
auth: `${prefix}/auth`,
68+
ui: `${prefix}/ui`,
6869
graphql: hasGraphQL ? `${prefix}/graphql` : undefined,
6970
storage: hasFiles ? `${prefix}/storage` : undefined,
7071
analytics: hasAnalytics ? `${prefix}/analytics` : undefined,
@@ -450,6 +451,33 @@ export class HttpDispatcher {
450451
return { handled: false };
451452
}
452453

454+
/**
455+
* Handles UI requests
456+
* path: sub-path after /ui/
457+
*/
458+
async handleUi(path: string, _context: HttpProtocolContext): Promise<HttpDispatcherResult> {
459+
const parts = path.replace(/^\/+/, '').split('/').filter(Boolean);
460+
461+
// GET /ui/view/:object/:type
462+
if (parts[0] === 'view' && parts.length === 3) {
463+
const [_, objectName, type] = parts;
464+
const protocol = this.kernel?.context?.getService ? this.kernel.context.getService('protocol') : null;
465+
466+
if (protocol && typeof protocol.getUiView === 'function') {
467+
try {
468+
const result = await protocol.getUiView({ object: objectName, type });
469+
return { handled: true, response: this.success(result) };
470+
} catch (e: any) {
471+
return { handled: true, response: this.error(e.message, 500) };
472+
}
473+
} else {
474+
return { handled: true, response: this.error('Protocol service not available', 503) };
475+
}
476+
}
477+
478+
return { handled: false };
479+
}
480+
453481
/**
454482
* Handles Automation requests
455483
* path: sub-path after /automation/
@@ -521,6 +549,10 @@ export class HttpDispatcher {
521549
return this.handleStorage(cleanPath.substring(8), method, body, context); // body here is file/stream for upload
522550
}
523551

552+
if (cleanPath.startsWith('/ui')) {
553+
return this.handleUi(cleanPath.substring(3), context);
554+
}
555+
524556
if (cleanPath.startsWith('/automation')) {
525557
return this.handleAutomation(cleanPath.substring(11), method, body, context);
526558
}

0 commit comments

Comments
 (0)