bun-router 0.2.6 → 0.2.8

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.
@@ -0,0 +1,9 @@
1
+ import { router, html, json } from '..';
2
+
3
+ const r = router();
4
+
5
+ const aliens = '👽'.repeat(30);
6
+
7
+ r.add('/space', 'GET', () => html(`<h1>${aliens}</h1>`))
8
+
9
+ r.serve();
@@ -72,7 +72,7 @@ const extractParams = (route: Route, req: HttpRequest) => {
72
72
  }
73
73
 
74
74
  const match = (route: Route, req: HttpRequest): boolean => {
75
- return req.params.size !== 0 || route.method === req.request.method
75
+ return req.params.size !== 0 || route.pattern === (new URL(req.request.url)).pathname
76
76
  }
77
77
 
78
78
  const router: Router = (port?: number | string, options?: Options) => {
@@ -101,6 +101,10 @@ const router: Router = (port?: number | string, options?: Options) => {
101
101
 
102
102
  extractParams(route, httpRequest);
103
103
 
104
+ if (match(route, httpRequest))
105
+ return route.callback(httpRequest);
106
+
107
+
104
108
  if (match(route, httpRequest)) return route.callback(httpRequest);
105
109
  }
106
110
  return new Response('not found');
package/package.json CHANGED
@@ -8,5 +8,5 @@
8
8
  "peerDependencies": {
9
9
  "typescript": "^5.0.0"
10
10
  },
11
- "version": "0.2.6"
11
+ "version": "0.2.8"
12
12
  }