bxo 0.0.5-dev.14 → 0.0.5-dev.15
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 +9 -9
- package/package.json +1 -1
package/index.ts
CHANGED
@@ -43,7 +43,7 @@ export type Context<TConfig extends RouteConfig = {}> = {
|
|
43
43
|
};
|
44
44
|
|
45
45
|
// Handler function type
|
46
|
-
type Handler<TConfig extends RouteConfig = {}> = (ctx: Context<TConfig>) => Promise<any> | any;
|
46
|
+
type Handler<TConfig extends RouteConfig = {}, EC = {}> = (ctx: Context<TConfig> & EC) => Promise<any> | any;
|
47
47
|
|
48
48
|
// Route definition
|
49
49
|
interface Route {
|
@@ -251,7 +251,7 @@ export default class BXO {
|
|
251
251
|
// Route matching utility
|
252
252
|
private matchRoute(method: string, pathname: string): { route: Route; params: Record<string, string> } | null {
|
253
253
|
const allRoutes = this.getAllRoutes();
|
254
|
-
|
254
|
+
|
255
255
|
for (const route of allRoutes) {
|
256
256
|
if (route.method !== method) continue;
|
257
257
|
|
@@ -263,7 +263,7 @@ export default class BXO {
|
|
263
263
|
|
264
264
|
// Handle wildcard at the end (catch-all)
|
265
265
|
const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
|
266
|
-
|
266
|
+
|
267
267
|
if (hasWildcardAtEnd) {
|
268
268
|
// For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
|
269
269
|
if (pathSegments.length < routeSegments.length - 1) continue;
|
@@ -317,7 +317,7 @@ export default class BXO {
|
|
317
317
|
// WebSocket route matching utility
|
318
318
|
private matchWSRoute(pathname: string): { route: WSRoute; params: Record<string, string> } | null {
|
319
319
|
const allWSRoutes = this.getAllWSRoutes();
|
320
|
-
|
320
|
+
|
321
321
|
for (const route of allWSRoutes) {
|
322
322
|
const routeSegments = route.path.split('/').filter(Boolean);
|
323
323
|
const pathSegments = pathname.split('/').filter(Boolean);
|
@@ -327,7 +327,7 @@ export default class BXO {
|
|
327
327
|
|
328
328
|
// Handle wildcard at the end (catch-all)
|
329
329
|
const hasWildcardAtEnd = routeSegments.length > 0 && routeSegments[routeSegments.length - 1] === '*';
|
330
|
-
|
330
|
+
|
331
331
|
if (hasWildcardAtEnd) {
|
332
332
|
// For catch-all wildcard, path must have at least as many segments as route (minus the wildcard)
|
333
333
|
if (pathSegments.length < routeSegments.length - 1) continue;
|
@@ -748,7 +748,7 @@ export default class BXO {
|
|
748
748
|
}));
|
749
749
|
|
750
750
|
// Get routes from all plugins
|
751
|
-
const pluginRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
|
751
|
+
const pluginRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
|
752
752
|
plugin._routes.map((route: Route) => ({
|
753
753
|
method: route.method,
|
754
754
|
path: route.path,
|
@@ -777,7 +777,7 @@ export default class BXO {
|
|
777
777
|
}));
|
778
778
|
|
779
779
|
// Get WebSocket routes from all plugins
|
780
|
-
const pluginWsRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
|
780
|
+
const pluginWsRoutes = this.plugins.flatMap((plugin, pluginIndex) =>
|
781
781
|
plugin._wsRoutes.map((route: WSRoute) => ({
|
782
782
|
path: route.path,
|
783
783
|
hasHandlers: {
|
@@ -802,7 +802,7 @@ const error = (error: Error | string, status: number = 500) => {
|
|
802
802
|
// File helper function (like Elysia)
|
803
803
|
const file = (path: string, options?: { type?: string; headers?: Record<string, string> }) => {
|
804
804
|
const bunFile = Bun.file(path);
|
805
|
-
|
805
|
+
|
806
806
|
if (options?.type) {
|
807
807
|
// Create a wrapper to override the MIME type
|
808
808
|
return {
|
@@ -811,7 +811,7 @@ const file = (path: string, options?: { type?: string; headers?: Record<string,
|
|
811
811
|
headers: options.headers
|
812
812
|
};
|
813
813
|
}
|
814
|
-
|
814
|
+
|
815
815
|
return bunFile;
|
816
816
|
}
|
817
817
|
|