bxo 0.0.5-dev.30 → 0.0.5-dev.32

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 +16 -48
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -340,7 +340,7 @@ export default class BXO {
340
340
  if (routeSegment === '*' && i === routeSegments.length - 1) {
341
341
  // Wildcard at end matches remaining path segments
342
342
  const remainingPath = pathSegments.slice(i).join('/');
343
- params['*'] = decodeURIComponent(remainingPath);
343
+ params['*'] = remainingPath;
344
344
  break;
345
345
  }
346
346
 
@@ -351,11 +351,11 @@ export default class BXO {
351
351
 
352
352
  if (routeSegment.startsWith(':')) {
353
353
  const paramName = routeSegment.slice(1);
354
- params[paramName] = decodeURIComponent(pathSegment);
354
+ params[paramName] = pathSegment;
355
355
  } else if (routeSegment === '*') {
356
356
  // Single segment wildcard
357
- params['*'] = decodeURIComponent(pathSegment);
358
- } else if (routeSegment !== decodeURIComponent(pathSegment)) {
357
+ params['*'] = pathSegment;
358
+ } else if (routeSegment !== pathSegment) {
359
359
  isMatch = false;
360
360
  break;
361
361
  }
@@ -404,7 +404,7 @@ export default class BXO {
404
404
  if (routeSegment === '*' && i === routeSegments.length - 1) {
405
405
  // Wildcard at end matches remaining path segments
406
406
  const remainingPath = pathSegments.slice(i).join('/');
407
- params['*'] = decodeURIComponent(remainingPath);
407
+ params['*'] = remainingPath;
408
408
  break;
409
409
  }
410
410
 
@@ -415,11 +415,11 @@ export default class BXO {
415
415
 
416
416
  if (routeSegment.startsWith(':')) {
417
417
  const paramName = routeSegment.slice(1);
418
- params[paramName] = decodeURIComponent(pathSegment);
418
+ params[paramName] = pathSegment;
419
419
  } else if (routeSegment === '*') {
420
420
  // Single segment wildcard
421
- params['*'] = decodeURIComponent(pathSegment);
422
- } else if (routeSegment !== decodeURIComponent(pathSegment)) {
421
+ params['*'] = pathSegment;
422
+ } else if (routeSegment !== pathSegment) {
423
423
  isMatch = false;
424
424
  break;
425
425
  }
@@ -510,7 +510,13 @@ export default class BXO {
510
510
  private async handleRequest(request: Request, server?: any): Promise<Response | undefined> {
511
511
  const url = new URL(request.url);
512
512
  const method = request.method;
513
- const pathname = url.pathname;
513
+ const rawPathname = url.pathname;
514
+ let pathname: string;
515
+ try {
516
+ pathname = decodeURI(rawPathname);
517
+ } catch {
518
+ pathname = rawPathname;
519
+ }
514
520
 
515
521
  // Check for WebSocket upgrade
516
522
  if (request.headers.get('upgrade') === 'websocket') {
@@ -636,15 +642,6 @@ export default class BXO {
636
642
  // Execute route handler
637
643
  let response = await route.handler(ctx);
638
644
 
639
- // If handler returned a Response, expose its status and headers to hooks
640
- if (response instanceof Response) {
641
- if (ctx.set.status === undefined) {
642
- ctx.set.status = response.status;
643
- }
644
- const existingHeaders = Object.fromEntries(response.headers);
645
- ctx.set.headers = { ...(existingHeaders || {}), ...(ctx.set.headers || {}) };
646
- }
647
-
648
645
  // Run global onResponse hook
649
646
  if (this.hooks.onResponse) {
650
647
  response = await this.hooks.onResponse(ctx, response, this) || response;
@@ -692,36 +689,7 @@ export default class BXO {
692
689
 
693
690
  // Convert response to Response object
694
691
  if (response instanceof Response) {
695
- // Merge existing response headers with any set via hooks
696
- let responseHeaders: Record<string, string> = {
697
- ...Object.fromEntries(response.headers),
698
- ...(ctx.set.headers || {})
699
- };
700
-
701
- // Handle cookies if any are set
702
- if (ctx.set.cookies && ctx.set.cookies.length > 0) {
703
- const cookieHeaders = ctx.set.cookies.map(cookie => {
704
- let cookieString = `${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}`;
705
-
706
- if (cookie.domain) cookieString += `; Domain=${cookie.domain}`;
707
- if (cookie.path) cookieString += `; Path=${cookie.path}`;
708
- if (cookie.expires) cookieString += `; Expires=${cookie.expires.toUTCString()}`;
709
- if (cookie.maxAge) cookieString += `; Max-Age=${cookie.maxAge}`;
710
- if (cookie.secure) cookieString += `; Secure`;
711
- if (cookie.httpOnly) cookieString += `; HttpOnly`;
712
- if (cookie.sameSite) cookieString += `; SameSite=${cookie.sameSite}`;
713
-
714
- return cookieString;
715
- });
716
-
717
- // Add Set-Cookie headers
718
- cookieHeaders.forEach((cookieHeader, index) => {
719
- responseHeaders[index === 0 ? 'Set-Cookie' : `Set-Cookie-${index}`] = cookieHeader;
720
- });
721
- }
722
-
723
- const mergedStatus = ctx.set.status || response.status || 200;
724
- return new Response(response.body, { status: mergedStatus, headers: responseHeaders });
692
+ return response;
725
693
  }
726
694
 
727
695
  // Handle File response (like Elysia)
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.30",
4
+ "version": "0.0.5-dev.32",
5
5
  "description": "A simple and lightweight web framework for Bun",
6
6
  "type": "module",
7
7
  "devDependencies": {