Skip to content

Commit 7f2bb0d

Browse files
committed
refactor: conditionally initialize Mock Service Worker and update path resolution in ConsolePlugin
1 parent e988ac3 commit 7f2bb0d

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

apps/console/src/main.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import { startMockServer } from './mocks/browser';
1212

1313
// Start MSW before rendering the app
1414
async function bootstrap() {
15-
// Initialize Mock Service Worker
16-
await startMockServer();
15+
// Initialize Mock Service Worker if enabled
16+
if (import.meta.env.VITE_USE_MOCK_SERVER !== 'false') {
17+
await startMockServer();
18+
}
1719

1820
// Render the React app
1921
ReactDOM.createRoot(document.getElementById('root')!).render(

apps/console/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

examples/crm/console-plugin.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11

22
import { serveStatic } from '@hono/node-server/serve-static';
33
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
import { dirname } from 'path';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename);
49

510
export class ConsolePlugin {
611
name = 'com.objectstack.server.console';
@@ -24,9 +29,9 @@ export class ConsolePlugin {
2429

2530
ctx.logger.info('Registering Console UI at /console');
2631

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');
32+
// Path relative to this file (examples/crm/console-plugin.ts)
33+
// ../../apps/console/dist
34+
const consoleDist = path.resolve(__dirname, '../../apps/console/dist');
3035

3136
// Serve static resources (JS, CSS, etc)
3237
// Hono serveStatic will look for the file in root

0 commit comments

Comments
 (0)