Skip to content

Commit e988ac3

Browse files
committed
feat: add ConsolePlugin for serving console UI and static assets
1 parent 880a99e commit e988ac3

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

examples/crm/console-plugin.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
import { serveStatic } from '@hono/node-server/serve-static';
3+
import path from 'path';
4+
5+
export class ConsolePlugin {
6+
name = 'com.objectstack.server.console';
7+
version = '1.0.0';
8+
9+
async init(ctx: any) {
10+
// No init logic needed
11+
}
12+
13+
async start(ctx: any) {
14+
const httpServer = ctx.getService('http-server');
15+
if (!httpServer) {
16+
ctx.logger.warn('HTTP Server not found, accessing console skipped');
17+
return;
18+
}
19+
20+
// We know it's HonoHttpServer from @objectstack/plugin-hono-server
21+
// It has getRawApp()
22+
if (typeof httpServer.getRawApp === 'function') {
23+
const app = httpServer.getRawApp();
24+
25+
ctx.logger.info('Registering Console UI at /console');
26+
27+
// Path relative to where server.ts is run (examples/crm)
28+
// apps is ../../apps
29+
const consoleDist = path.resolve(process.cwd(), '../../apps/console/dist');
30+
31+
// Serve static resources (JS, CSS, etc)
32+
// Hono serveStatic will look for the file in root
33+
// If we request /console/assets/foo.js, we want to serve /dist/assets/foo.js
34+
app.use('/console/*', serveStatic({
35+
root: consoleDist,
36+
rewriteRequestPath: (path: string) => path.replace(/^\/console/, '')
37+
}));
38+
39+
// Fallback for SPA routing: any non-file request under /console returns index.html
40+
app.get('/console/*', serveStatic({
41+
root: consoleDist,
42+
rewriteRequestPath: () => '/index.html'
43+
}));
44+
45+
ctx.logger.info(`✅ Console available at http://localhost:3000/console`);
46+
} else {
47+
ctx.logger.warn('HTTP Server does not support getRawApp()');
48+
}
49+
}
50+
}

examples/crm/server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
66
import { InMemoryDriver } from '@objectstack/driver-memory';
77
import config from './objectstack.config';
88
import { pino } from 'pino';
9+
import { ConsolePlugin } from './console-plugin';
910

1011
async function startServer() {
1112
const logger = pino({
@@ -44,6 +45,10 @@ async function startServer() {
4445
const serverPlugin = new HonoServerPlugin({ port: 3000 });
4546
kernel.use(serverPlugin);
4647

48+
// 5. Console Plugin
49+
const consolePlugin = new ConsolePlugin();
50+
kernel.use(consolePlugin);
51+
4752
// Bootstrap
4853
await kernel.bootstrap();
4954

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@
115115
}
116116
},
117117
"dependencies": {
118+
"@hono/node-server": "^1.19.9",
118119
"@objectstack/plugin-hono-server": "^0.8.0",
119120
"coverage-v8": "0.0.1-security",
121+
"hono": "^4.11.7",
120122
"pino": "^8.21.0",
121123
"pino-pretty": "^13.1.3"
122124
},

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)