bxo 0.0.5-dev.1 → 0.0.5-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +60 -7
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -53,7 +53,7 @@ interface LifecycleHooks {
53
53
  }
54
54
 
55
55
  export default class BXO {
56
- private routes: Route[] = [];
56
+ private _routes: Route[] = [];
57
57
  private plugins: BXO[] = [];
58
58
  private hooks: LifecycleHooks = {};
59
59
  private server?: any;
@@ -61,6 +61,8 @@ export default class BXO {
61
61
  private hotReloadEnabled: boolean = false;
62
62
  private watchedFiles: Set<string> = new Set();
63
63
  private watchedExclude: Set<string> = new Set();
64
+ private serverPort?: number;
65
+ private serverHostname?: string;
64
66
 
65
67
  constructor() { }
66
68
 
@@ -131,7 +133,7 @@ export default class BXO {
131
133
  handler: Handler<TConfig>,
132
134
  config?: TConfig
133
135
  ): this {
134
- this.routes.push({ method: 'GET', path, handler, config });
136
+ this._routes.push({ method: 'GET', path, handler, config });
135
137
  return this;
136
138
  }
137
139
 
@@ -149,7 +151,7 @@ export default class BXO {
149
151
  handler: Handler<TConfig>,
150
152
  config?: TConfig
151
153
  ): this {
152
- this.routes.push({ method: 'POST', path, handler, config });
154
+ this._routes.push({ method: 'POST', path, handler, config });
153
155
  return this;
154
156
  }
155
157
 
@@ -167,7 +169,7 @@ export default class BXO {
167
169
  handler: Handler<TConfig>,
168
170
  config?: TConfig
169
171
  ): this {
170
- this.routes.push({ method: 'PUT', path, handler, config });
172
+ this._routes.push({ method: 'PUT', path, handler, config });
171
173
  return this;
172
174
  }
173
175
 
@@ -185,7 +187,7 @@ export default class BXO {
185
187
  handler: Handler<TConfig>,
186
188
  config?: TConfig
187
189
  ): this {
188
- this.routes.push({ method: 'DELETE', path, handler, config });
190
+ this._routes.push({ method: 'DELETE', path, handler, config });
189
191
  return this;
190
192
  }
191
193
 
@@ -203,13 +205,13 @@ export default class BXO {
203
205
  handler: Handler<TConfig>,
204
206
  config?: TConfig
205
207
  ): this {
206
- this.routes.push({ method: 'PATCH', path, handler, config });
208
+ this._routes.push({ method: 'PATCH', path, handler, config });
207
209
  return this;
208
210
  }
209
211
 
210
212
  // Route matching utility
211
213
  private matchRoute(method: string, pathname: string): { route: Route; params: Record<string, string> } | null {
212
- for (const route of this.routes) {
214
+ for (const route of this._routes) {
213
215
  if (route.method !== method) continue;
214
216
 
215
217
  const routeSegments = route.path.split('/').filter(Boolean);
@@ -501,6 +503,8 @@ export default class BXO {
501
503
  });
502
504
 
503
505
  this.isRunning = true;
506
+ this.serverPort = port;
507
+ this.serverHostname = hostname;
504
508
 
505
509
  console.log(`🦊 BXO server running at http://${hostname}:${port}`);
506
510
 
@@ -545,6 +549,8 @@ export default class BXO {
545
549
  }
546
550
 
547
551
  this.isRunning = false;
552
+ this.serverPort = undefined;
553
+ this.serverHostname = undefined;
548
554
 
549
555
  console.log('🛑 BXO server stopped');
550
556
 
@@ -604,6 +610,53 @@ export default class BXO {
604
610
  excludePatterns: Array.from(this.watchedExclude)
605
611
  };
606
612
  }
613
+
614
+ // Get server information (alias for getServerInfo)
615
+ get info() {
616
+ return {
617
+ // Server status
618
+ running: this.isRunning,
619
+ server: this.server ? 'Bun' : null,
620
+
621
+ // Connection details
622
+ hostname: this.serverHostname,
623
+ port: this.serverPort,
624
+ url: this.isRunning && this.serverHostname && this.serverPort
625
+ ? `http://${this.serverHostname}:${this.serverPort}`
626
+ : null,
627
+
628
+ // Application statistics
629
+ totalRoutes: this._routes.length,
630
+ totalPlugins: this.plugins.length,
631
+
632
+ // Hot reload configuration
633
+ hotReload: this.hotReloadEnabled,
634
+ watchedFiles: Array.from(this.watchedFiles),
635
+ excludePatterns: Array.from(this.watchedExclude),
636
+
637
+ // System information
638
+ runtime: 'Bun',
639
+ version: typeof Bun !== 'undefined' ? Bun.version : 'unknown',
640
+ pid: process.pid,
641
+ uptime: this.isRunning ? process.uptime() : 0
642
+ };
643
+ }
644
+
645
+ // Get all routes information
646
+ get routes() {
647
+ return this._routes.map((route: Route) => ({
648
+ method: route.method,
649
+ path: route.path,
650
+ hasConfig: !!route.config,
651
+ config: route.config ? {
652
+ hasParams: !!route.config.params,
653
+ hasQuery: !!route.config.query,
654
+ hasBody: !!route.config.body,
655
+ hasHeaders: !!route.config.headers,
656
+ hasResponse: !!route.config.response
657
+ } : null
658
+ }));
659
+ }
607
660
  }
608
661
 
609
662
  const error = (error: Error, status: number = 500) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bxo",
3
3
  "module": "index.ts",
4
- "version": "0.0.5-dev.1",
4
+ "version": "0.0.5-dev.3",
5
5
  "description": "A simple and lightweight web framework for Bun",
6
6
  "type": "module",
7
7
  "devDependencies": {