bxo 0.0.5-dev.5 → 0.0.5-dev.7

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 +61 -16
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -360,7 +360,7 @@ export default class BXO {
360
360
  pathname
361
361
  }
362
362
  });
363
-
363
+
364
364
  if (success) {
365
365
  return; // undefined response means upgrade was successful
366
366
  }
@@ -451,6 +451,35 @@ export default class BXO {
451
451
  return response;
452
452
  }
453
453
 
454
+ // Handle File response (like Elysia)
455
+ if (response instanceof File || (typeof Bun !== 'undefined' && response instanceof Bun.file('').constructor)) {
456
+ const file = response as File;
457
+ const responseInit: ResponseInit = {
458
+ status: ctx.set.status || 200,
459
+ headers: {
460
+ 'Content-Type': file.type || 'application/octet-stream',
461
+ 'Content-Length': file.size.toString(),
462
+ ...ctx.set.headers
463
+ }
464
+ };
465
+ return new Response(file, responseInit);
466
+ }
467
+
468
+ // Handle Bun.file() response
469
+ if (typeof response === 'object' && response && 'stream' in response && 'size' in response) {
470
+ const bunFile = response as any;
471
+ const responseInit: ResponseInit = {
472
+ status: ctx.set.status || 200,
473
+ headers: {
474
+ 'Content-Type': bunFile.type || 'application/octet-stream',
475
+ 'Content-Length': bunFile.size?.toString() || '',
476
+ ...ctx.set.headers,
477
+ ...(bunFile.headers || {}) // Support custom headers from file helper
478
+ }
479
+ };
480
+ return new Response(bunFile, responseInit);
481
+ }
482
+
454
483
  const responseInit: ResponseInit = {
455
484
  status: ctx.set.status || 200,
456
485
  headers: ctx.set.headers || {}
@@ -515,14 +544,14 @@ export default class BXO {
515
544
  if (pattern === filename) {
516
545
  return true;
517
546
  }
518
-
547
+
519
548
  // Handle directory patterns (e.g., "node_modules/", "dist/")
520
549
  if (pattern.endsWith('/')) {
521
550
  if (filename.startsWith(pattern) || filename.includes(`/${pattern}`)) {
522
551
  return true;
523
552
  }
524
553
  }
525
-
554
+
526
555
  // Handle wildcard patterns (e.g., "*.log", "temp*")
527
556
  if (pattern.includes('*')) {
528
557
  const regex = new RegExp(pattern.replace(/\*/g, '.*'));
@@ -530,18 +559,18 @@ export default class BXO {
530
559
  return true;
531
560
  }
532
561
  }
533
-
562
+
534
563
  // Handle file extension patterns (e.g., ".log", ".tmp")
535
564
  if (pattern.startsWith('.') && filename.endsWith(pattern)) {
536
565
  return true;
537
566
  }
538
-
567
+
539
568
  // Handle substring matches for directories
540
569
  if (filename.includes(pattern)) {
541
570
  return true;
542
571
  }
543
572
  }
544
-
573
+
545
574
  return false;
546
575
  }
547
576
 
@@ -558,7 +587,7 @@ export default class BXO {
558
587
  if (this.shouldExcludeFile(filename)) {
559
588
  return;
560
589
  }
561
-
590
+
562
591
  console.log(`🔄 File changed: ${filename}, restarting server...`);
563
592
  await this.restart(port, hostname);
564
593
  }
@@ -727,24 +756,24 @@ export default class BXO {
727
756
  // Server status
728
757
  running: this.isRunning,
729
758
  server: this.server ? 'Bun' : null,
730
-
759
+
731
760
  // Connection details
732
761
  hostname: this.serverHostname,
733
762
  port: this.serverPort,
734
- url: this.isRunning && this.serverHostname && this.serverPort
735
- ? `http://${this.serverHostname}:${this.serverPort}`
763
+ url: this.isRunning && this.serverHostname && this.serverPort
764
+ ? `http://${this.serverHostname}:${this.serverPort}`
736
765
  : null,
737
-
766
+
738
767
  // Application statistics
739
768
  totalRoutes: this._routes.length,
740
769
  totalWsRoutes: this._wsRoutes.length,
741
770
  totalPlugins: this.plugins.length,
742
-
771
+
743
772
  // Hot reload configuration
744
773
  hotReload: this.hotReloadEnabled,
745
774
  watchedFiles: Array.from(this.watchedFiles),
746
775
  excludePatterns: Array.from(this.watchedExclude),
747
-
776
+
748
777
  // System information
749
778
  runtime: 'Bun',
750
779
  version: typeof Bun !== 'undefined' ? Bun.version : 'unknown',
@@ -777,12 +806,28 @@ export default class BXO {
777
806
  }
778
807
  }
779
808
 
780
- const error = (error: Error, status: number = 500) => {
781
- return new Response(JSON.stringify({ error: error.message }), { status });
809
+ const error = (error: Error | string, status: number = 500) => {
810
+ return new Response(JSON.stringify({ error: error instanceof Error ? error.message : error }), { status });
811
+ }
812
+
813
+ // File helper function (like Elysia)
814
+ const file = (path: string, options?: { type?: string; headers?: Record<string, string> }) => {
815
+ const bunFile = Bun.file(path);
816
+
817
+ if (options?.type) {
818
+ // Create a wrapper to override the MIME type
819
+ return {
820
+ ...bunFile,
821
+ type: options.type,
822
+ headers: options.headers
823
+ };
824
+ }
825
+
826
+ return bunFile;
782
827
  }
783
828
 
784
829
  // Export Zod for convenience
785
- export { z, error };
830
+ export { z, error, file };
786
831
 
787
832
  // Export types for external use
788
833
  export type { RouteConfig, RouteDetail, Handler, WebSocketHandler, WSRoute };
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.5",
4
+ "version": "0.0.5-dev.7",
5
5
  "description": "A simple and lightweight web framework for Bun",
6
6
  "type": "module",
7
7
  "devDependencies": {