Skip to content

Commit 208919c

Browse files
committed
feat: add multi-project support for runtime configuration and templates endpoint
1 parent f700c48 commit 208919c

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

apps/server/server/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ObjectKernel, createRestApiPlugin, createDispatcherPlugin, KernelManage
1717
import type { EnvironmentDriverRegistry } from '@objectstack/runtime';
1818
import type { Hono } from 'hono';
1919
import stackConfig from '../objectstack.config.js';
20+
import { listTemplates } from './templates/registry.js';
2021

2122
// ---------------------------------------------------------------------------
2223
// Runtime shape returned by ensureBoot()
@@ -106,6 +107,10 @@ async function ensureBoot(): Promise<BootResult> {
106107
// Hono app factory
107108
// ---------------------------------------------------------------------------
108109

110+
function envFlag(name: string): boolean {
111+
return ['1', 'true', 'yes', 'on'].includes((process.env[name] ?? '').trim().toLowerCase());
112+
}
113+
109114
async function ensureApp(): Promise<Hono> {
110115
if (_app) return _app;
111116

@@ -114,6 +119,29 @@ async function ensureApp(): Promise<Hono> {
114119
// kernel's service registry (MultiProjectPlugin registered them during
115120
// bootKernel), so they do NOT need to be passed explicitly here.
116121
_app = createHonoApp({ kernel, prefix: '/api/v1' });
122+
123+
// Vercel entrypoint does NOT load plugin-hono-server, so the
124+
// `http.server` service is never registered. The route plugins in
125+
// `multi-project-plugins.ts` early-return when that service is
126+
// missing, leaving `/studio/runtime-config` and `/cloud/templates`
127+
// unmounted (404 / empty list). Mount them directly on the Hono
128+
// instance here so multi-project deployments behave correctly.
129+
if (envFlag('OBJECTSTACK_MULTI_PROJECT')) {
130+
const templatesPayload = listTemplates().map(({ id, label, description, category }) => ({
131+
id,
132+
label,
133+
description,
134+
category,
135+
}));
136+
_app.get('/api/v1/studio/runtime-config', (c) =>
137+
c.json({ singleProject: false }));
138+
_app.get('/api/v1/cloud/templates', (c) =>
139+
c.json({
140+
success: true,
141+
data: { templates: templatesPayload, total: templatesPayload.length },
142+
}));
143+
}
144+
117145
return _app;
118146
}
119147

0 commit comments

Comments
 (0)