1+
12import { createRequire } from 'module' ;
23const require = createRequire ( import . meta. url ) ;
34// @ts -ignore
45globalThis . require = require ;
56
67import { defineConfig } from './src/config' ;
8+ import { sharedConfig } from './objectstack.shared' ;
9+
710// @ts -ignore
811import * as MSWPluginPkg from '@objectstack/plugin-msw' ;
912// @ts -ignore
@@ -15,6 +18,8 @@ const MSWPlugin = MSWPluginPkg.MSWPlugin || (MSWPluginPkg as any).default?.MSWPl
1518const ObjectQLPlugin = ObjectQLPluginPkg . ObjectQLPlugin || ( ObjectQLPluginPkg as any ) . default ?. ObjectQLPlugin || ( ObjectQLPluginPkg as any ) . default ;
1619const HonoServerPlugin = HonoServerPluginPkg . HonoServerPlugin || ( HonoServerPluginPkg as any ) . default ?. HonoServerPlugin || ( HonoServerPluginPkg as any ) . default ;
1720
21+ import ConsolePluginConfig from './plugin.js' ;
22+
1823// FIX: Ensure init is own property for runtime compatibility
1924class PatchedMSWPlugin extends MSWPlugin {
2025 constructor ( ...args : any [ ] ) {
@@ -31,55 +36,55 @@ class PatchedHonoServerPlugin extends HonoServerPlugin {
3136 super ( ...args ) ;
3237 // @ts -ignore
3338 this . init = this . init . bind ( this ) ;
34- // @ts -ignore
35- this . start = this . start ?. bind ( this ) ;
36- }
37-
38- async start ( ctx : any ) {
39- // @ts -ignore
40- await super . start ( ctx ) ;
4139
42- // SPA Fallback: Serve index.html for unknown routes (excluding /api )
40+ // Capture original start method (which is an arrow function property )
4341 // @ts -ignore
44- const app = this . server . getRawApp ( ) ;
42+ const originalStart = this . start ;
43+
44+ // Override start with custom logic
4545 // @ts -ignore
46- const staticRoot = this . options . staticRoot ;
47-
48- if ( staticRoot ) {
49- const fs = require ( 'fs' ) ;
50- const path = require ( 'path' ) ;
46+ this . start = async ( ctx : any ) => {
47+ // Call original start
48+ if ( originalStart ) {
49+ await originalStart ( ctx ) ;
50+ }
51+
52+ // SPA Fallback: Serve index.html for unknown routes (excluding /api)
53+ // @ts -ignore
54+ const app = this . server . getRawApp ( ) ;
55+ // @ts -ignore
56+ const staticRoot = this . options . staticRoot ;
5157
52- // Register fallback after serveStatic (which is added in listen/super.start)
53- app . get ( '*' , async ( c : any ) => {
54- // Ignore API calls -> let them 404
55- if ( c . req . path . startsWith ( '/api' ) || c . req . path . startsWith ( '/assets' ) ) {
56- // return c.notFound(); // Hono's c.notFound() isn't standard in all versions, let's use status
57- return c . text ( 'Not Found' , 404 ) ;
58- }
58+ if ( staticRoot ) {
59+ const fs = require ( 'fs' ) ;
60+ const path = require ( 'path' ) ;
5961
60- try {
61- // Try to serve index.html
62- // Ensure we resolve relative to CWD or config location
63- const indexPath = path . resolve ( staticRoot , 'index.html' ) ;
64- if ( fs . existsSync ( indexPath ) ) {
65- const indexContent = fs . readFileSync ( indexPath , 'utf-8' ) ;
66- return c . html ( indexContent ) ;
62+ // Register fallback after serveStatic (which is added in listen/originalStart)
63+ app . get ( '*' , async ( c : any ) => {
64+ // Ignore API calls -> let them 404
65+ if ( c . req . path . startsWith ( '/api' ) || c . req . path . startsWith ( '/assets' ) ) {
66+ return c . text ( 'Not Found' , 404 ) ;
6767 }
68- return c . text ( 'SPA Index Not Found' , 404 ) ;
69- } catch ( e : any ) {
70- return c . text ( 'Server Error: ' + e . message , 500 ) ;
71- }
72- } ) ;
73- console . log ( 'SPA Fallback route registered for ' + staticRoot ) ;
74- }
68+
69+ try {
70+ // Try to serve index.html
71+ // Ensure we resolve relative to CWD or config location
72+ const indexPath = path . resolve ( staticRoot , 'index.html' ) ;
73+ if ( fs . existsSync ( indexPath ) ) {
74+ const indexContent = fs . readFileSync ( indexPath , 'utf-8' ) ;
75+ return c . html ( indexContent ) ;
76+ }
77+ return c . text ( 'SPA Index Not Found' , 404 ) ;
78+ } catch ( e : any ) {
79+ return c . text ( 'Server Error: ' + e . message , 500 ) ;
80+ }
81+ } ) ;
82+ console . log ( 'SPA Fallback route registered for ' + staticRoot ) ;
83+ }
84+ } ;
7585 }
7686}
7787
78- import ConsolePluginConfig from './plugin.js' ;
79- import crmConfig from '@object-ui/example-crm/objectstack.config' ;
80- import todoConfig from '@object-ui/example-todo/objectstack.config' ;
81- import kitchenSinkConfig from '@object-ui/example-kitchen-sink/objectstack.config' ;
82-
8388const FixedConsolePlugin = {
8489 ...ConsolePluginConfig ,
8590 init : ( ) => { }
@@ -91,7 +96,6 @@ const DummyApiRegistryPlugin = {
9196 version : '1.0.0' ,
9297 init : ( ctx : any ) => {
9398 // Polyfill missing critical services to pass the Runtime health check
94- // These are normally provided by standard plugins not currently included in this lightweight setup
9599
96100 ctx . registerService ( 'metadata' , {
97101 getApp : ( ) => null ,
@@ -117,15 +121,13 @@ const DummyApiRegistryPlugin = {
117121 const apiEndpoints : any [ ] = [ ] ;
118122 ctx . registerService ( 'api-registry' , {
119123 registerApi : ( entry : any ) => {
120- // console.log('Mock: Registering API', entry.id);
121124 apiEndpoints . push ( entry ) ;
122125 } ,
123126 getRegistry : ( ) => ( {
124127 apis : apiEndpoints ,
125128 totalApis : apiEndpoints . length ,
126129 totalEndpoints : apiEndpoints . reduce ( ( acc , api ) => acc + ( api . endpoints ?. length || 0 ) , 0 )
127130 } ) ,
128- // Add other potential methods if needed
129131 registerRoute : ( ) => { } ,
130132 getRoutes : ( ) => [ ]
131133 } ) ;
@@ -137,31 +139,21 @@ const DummyApiRegistryPlugin = {
137139
138140const plugins : any [ ] = [
139141 new ObjectQLPlugin ( ) ,
140- // new PatchedMSWPlugin(), // Disabled in production mode as per requirement
142+ // new PatchedMSWPlugin(), // Disabled in production mode
141143 new PatchedHonoServerPlugin ( {
142144 staticRoot : './dist'
143145 } ) ,
144146 FixedConsolePlugin ,
145147 DummyApiRegistryPlugin
146148] ;
147149
148- // Re-enable MSW only if explicitly needed (e.g. via test env var, though technically pnpm dev uses browser MSW)
150+ // Re-enable MSW only if explicitly needed
149151if ( process . env . ENABLE_MSW_PLUGIN === 'true' ) {
150152 plugins . push ( new PatchedMSWPlugin ( ) ) ;
151153}
152154
153155export default defineConfig ( {
154- // ============================================================================
155- // Project Metadata
156- // ============================================================================
157-
158- name : '@object-ui/console' ,
159- version : '0.1.0' ,
160- description : 'ObjectStack Console' ,
161-
162- // ============================================================================
163- // Build Settings
164- // ============================================================================
156+ ...sharedConfig ,
165157
166158 build : {
167159 outDir : './dist' ,
@@ -170,56 +162,13 @@ export default defineConfig({
170162 target : 'node18' ,
171163 } ,
172164
173- // ============================================================================
174- // Database Configuration
175- // ============================================================================
176-
177165 datasources : {
178166 default : {
179- driver : 'memory' , // Use memory driver for browser example
167+ driver : 'memory' ,
180168 } ,
181169 } ,
182170
183- // ============================================================================
184- // Plugin Configuration
185- // ============================================================================
186-
187171 plugins,
188-
189- // ============================================================================
190- // Merged Stack Configuration (CRM + Todo + Kitchen Sink + Mock Metadata)
191- // ============================================================================
192- objects : [
193- ...( crmConfig . objects || [ ] ) ,
194- ...( todoConfig . objects || [ ] ) ,
195- ...( kitchenSinkConfig . objects || [ ] )
196- ] ,
197- apps : [
198- ...( crmConfig . apps || [ ] ) ,
199- ...( todoConfig . apps || [ ] ) ,
200- ...( kitchenSinkConfig . apps || [ ] )
201- ] ,
202- dashboards : [
203- ...( crmConfig . dashboards || [ ] ) ,
204- ...( todoConfig . dashboards || [ ] ) ,
205- ...( kitchenSinkConfig . dashboards || [ ] )
206- ] ,
207- pages : [
208- ...( crmConfig . pages || [ ] ) ,
209- ...( todoConfig . pages || [ ] ) ,
210- ...( kitchenSinkConfig . pages || [ ] )
211- ] ,
212- manifest : {
213- data : [
214- ...( crmConfig . manifest ?. data || [ ] ) ,
215- ...( todoConfig . manifest ?. data || [ ] ) ,
216- ...( kitchenSinkConfig . manifest ?. data || [ ] )
217- ]
218- } ,
219-
220- // ============================================================================
221- // Development Server
222- // ============================================================================
223172
224173 dev : {
225174 port : 3000 ,
@@ -228,12 +177,8 @@ export default defineConfig({
228177 hotReload : true ,
229178 } ,
230179
231- // ============================================================================
232- // Deployment
233- // ============================================================================
234-
235180 deploy : {
236- target : 'static' , // This is a static SPA
181+ target : 'static' ,
237182 region : 'us-east-1' ,
238183 } ,
239184} ) ;
0 commit comments