bxo 0.0.5-dev.6 → 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.
- package/index.ts +46 -1
- package/package.json +1 -1
package/index.ts
CHANGED
@@ -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 || {}
|
@@ -781,8 +810,24 @@ const error = (error: Error | string, status: number = 500) => {
|
|
781
810
|
return new Response(JSON.stringify({ error: error instanceof Error ? error.message : error }), { status });
|
782
811
|
}
|
783
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;
|
827
|
+
}
|
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 };
|