Skip to content

Commit dc59963

Browse files
committed
重构开发服务器,删除 @objectstack/dev-server 包,添加 @objectstack/plugin-hono-server 插件以支持 Hono 框架;更新相关依赖和配置
1 parent f214964 commit dc59963

File tree

7 files changed

+55
-57
lines changed

7 files changed

+55
-57
lines changed

examples/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"@objectstack/runtime": "workspace:*",
1111
"@objectstack/driver-memory": "workspace:*",
12-
"@objectstack/dev-server": "workspace:*",
12+
"@objectstack/plugin-hono-server": "workspace:*",
1313
"@objectstack/example-crm": "workspace:*",
1414
"@objectstack/example-todo": "workspace:*",
1515
"@objectstack/plugin-bi": "workspace:*"

examples/server/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DataEngine } from '@objectstack/runtime';
22
import { InMemoryDriver } from '@objectstack/driver-memory';
3-
import { DevServerPlugin } from '@objectstack/dev-server';
3+
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
44

55
import CrmApp from '@objectstack/example-crm/objectstack.config';
66
import TodoApp from '@objectstack/example-todo/objectstack.config';
@@ -15,8 +15,11 @@ import BiPluginManifest from '@objectstack/plugin-bi/objectstack.config';
1515
BiPluginManifest,
1616
new InMemoryDriver(),
1717

18-
// Load the Dev Server Plugin
19-
new DevServerPlugin({ port: 3004 })
18+
// Load the Hono Server Plugin
19+
new HonoServerPlugin({
20+
port: 3004,
21+
staticRoot: './public'
22+
})
2023
]);
2124

2225
await kernel.start();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@objectstack/dev-server",
2+
"name": "@objectstack/plugin-hono-server",
33
"version": "0.1.0",
4-
"description": "Lightweight Development Server for ObjectStack UI Development",
4+
"description": "Standard Hono Server Adapter for ObjectStack Runtime",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
File renamed without changes.
Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,57 @@ import { cors } from 'hono/cors';
55
import { logger } from 'hono/logger';
66
import { DataEngine, ObjectStackRuntimeProtocol, RuntimePlugin } from '@objectstack/runtime';
77

8-
export interface DevServerOptions {
8+
export interface HonoServerOptions {
99
port?: number;
1010
staticRoot?: string;
1111
cors?: boolean;
12+
logger?: boolean;
1213
}
1314

1415
/**
15-
* ObjectStack Development Server Plugin
16+
* Hono Server Runtime Plugin
1617
*
17-
* Drop-in plugin to expose Kernel via HTTP for UI development.
18-
* NOT for production use.
18+
* Exposes the ObjectStack Kernel via standard HTTP Protocol using Hono.
19+
* Can be used for Production (Standalone) or Development.
1920
*/
20-
export class DevServerPlugin implements RuntimePlugin {
21-
name = 'dev-server';
22-
private port: number;
23-
private staticRoot: string;
24-
private enableCors: boolean;
21+
export class HonoServerPlugin implements RuntimePlugin {
22+
name = 'com.objectstack.server.hono';
23+
24+
private options: HonoServerOptions;
2525

26-
constructor(options: DevServerOptions = {}) {
27-
this.port = options.port || 3004;
28-
this.staticRoot = options.staticRoot || './public';
29-
this.enableCors = options.cors !== false;
26+
constructor(options: HonoServerOptions = {}) {
27+
this.options = {
28+
port: 3000,
29+
cors: true,
30+
logger: true,
31+
...options
32+
};
3033
}
3134

3235
async onStart(ctx: { engine: DataEngine }) {
3336
const app = new Hono();
3437
const protocol = new ObjectStackRuntimeProtocol(ctx.engine);
3538

36-
// 1. Dev Middlewares
37-
app.use('*', logger());
38-
if (this.enableCors) {
39-
app.use('*', cors());
40-
}
39+
// 1. Middlewares
40+
if (this.options.logger) app.use('*', logger());
41+
if (this.options.cors) app.use('*', cors());
4142

4243
// 2. Wiring Protocol (Automatic)
4344
// Discovery
4445
app.get('/api/v1', (c) => c.json(protocol.getDiscovery()));
4546

46-
// Meta (Types)
47+
// Meta Protocol
4748
app.get('/api/v1/meta', (c) => c.json(protocol.getMetaTypes()));
48-
// Meta (List)
4949
app.get('/api/v1/meta/:type', (c) => c.json(protocol.getMetaItems(c.req.param('type'))));
50-
// Meta (Item)
51-
app.get('/api/v1/meta/:type/:name', (c) => {
50+
app.get('/api/v1/meta/:type/:name', (c) => {
5251
try {
53-
return c.json(protocol.getMetaItem(c.req.param('type'), c.req.param('name')))
52+
return c.json(protocol.getMetaItem(c.req.param('type'), c.req.param('name')));
5453
} catch(e:any) {
5554
return c.json({error: e.message}, 404);
5655
}
5756
});
58-
59-
// Data (Read)
57+
58+
// Data Protocol
6059
app.get('/api/v1/data/:object', async (c) => {
6160
try { return c.json(await protocol.findData(c.req.param('object'), c.req.query())); }
6261
catch(e:any) { return c.json({error:e.message}, 400); }
@@ -65,8 +64,6 @@ export class DevServerPlugin implements RuntimePlugin {
6564
try { return c.json(await protocol.getData(c.req.param('object'), c.req.param('id'))); }
6665
catch(e:any) { return c.json({error:e.message}, 404); }
6766
});
68-
69-
// Data (Write)
7067
app.post('/api/v1/data/:object', async (c) => {
7168
try { return c.json(await protocol.createData(c.req.param('object'), await c.req.json()), 201); }
7269
catch(e:any) { return c.json({error:e.message}, 400); }
@@ -80,7 +77,7 @@ export class DevServerPlugin implements RuntimePlugin {
8077
catch(e:any) { return c.json({error:e.message}, 400); }
8178
});
8279

83-
// UI View
80+
// UI Protocol
8481
// @ts-ignore
8582
app.get('/api/v1/ui/view/:object', (c) => {
8683
try {
@@ -90,18 +87,16 @@ export class DevServerPlugin implements RuntimePlugin {
9087
catch(e:any) { return c.json({error:e.message}, 404); }
9188
});
9289

93-
// 3. Static Files (UI Hosting)
94-
if (this.staticRoot) {
95-
app.get('/', serveStatic({ root: this.staticRoot, path: 'index.html' }));
96-
app.get('/*', serveStatic({ root: this.staticRoot }));
90+
// 3. Static Files (Optional)
91+
if (this.options.staticRoot) {
92+
app.get('/', serveStatic({ root: this.options.staticRoot, path: 'index.html' }));
93+
app.get('/*', serveStatic({ root: this.options.staticRoot }));
9794
}
9895

9996
console.log('');
100-
console.log(`📦 ObjectStack Dev Server running at: http://localhost:${this.port}`);
101-
console.log(`➜ API Discovery: http://localhost:${this.port}/api/v1`);
102-
console.log(`➜ UI Playground: http://localhost:${this.port}/index.html`);
97+
console.log(`🌍 ObjectStack Server (Hono) running at: http://localhost:${this.options.port}`);
10398
console.log('');
104-
105-
serve({ fetch: app.fetch, port: this.port });
99+
100+
serve({ fetch: app.fetch, port: this.options.port });
106101
}
107102
}

pnpm-lock.yaml

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)