bun-router 0.7.4-experimental.2 → 0.7.4-experimental.3
Sign up to get free protection for your applications and to get access to all the features.
- package/examples/static.ts +1 -1
- package/lib/router/router.ts +6 -5
- package/package.json +4 -2
- package/tsconfig.json +1 -1
package/examples/static.ts
CHANGED
package/lib/router/router.ts
CHANGED
@@ -31,10 +31,9 @@ const Router: BunRouter = (port?: number | string, options?: RouterOptions<Optio
|
|
31
31
|
// the root directory is traversed recursively
|
32
32
|
static: async (pattern: string, root: string) => {
|
33
33
|
await readDir(root, async (fp) => {
|
34
|
-
const
|
35
|
-
const ext = path.extname(pure);
|
34
|
+
const ext = path.extname(fp);
|
36
35
|
|
37
|
-
let base = path.basename(
|
36
|
+
let base = path.basename(fp);
|
38
37
|
|
39
38
|
//FIXME: this can be improved
|
40
39
|
if (ext === '.html') base = base.replace(ext, '');
|
@@ -46,6 +45,8 @@ const Router: BunRouter = (port?: number | string, options?: RouterOptions<Optio
|
|
46
45
|
|
47
46
|
if (base === 'index') patternPath = pattern;
|
48
47
|
|
48
|
+
const purePath = path.join(root, patternPath);
|
49
|
+
|
49
50
|
const route: Route = {
|
50
51
|
children: new Map(),
|
51
52
|
dynamicPath: '',
|
@@ -54,10 +55,10 @@ const Router: BunRouter = (port?: number | string, options?: RouterOptions<Optio
|
|
54
55
|
method: 'GET',
|
55
56
|
handler: async () => {
|
56
57
|
if (ext === '.tsx') {
|
57
|
-
const component = await loadComponent(
|
58
|
+
const component = await loadComponent(purePath.split('.')[0]);
|
58
59
|
return await http.render(component());
|
59
60
|
} else {
|
60
|
-
return await http.file(200,
|
61
|
+
return await http.file(200, fp);
|
61
62
|
}
|
62
63
|
},
|
63
64
|
};
|
package/package.json
CHANGED
@@ -14,8 +14,10 @@
|
|
14
14
|
"peerDependencies": {
|
15
15
|
"typescript": "^5.0.0"
|
16
16
|
},
|
17
|
-
"version": "0.7.4-experimental.
|
17
|
+
"version": "0.7.4-experimental.3",
|
18
18
|
"dependencies": {
|
19
|
-
"
|
19
|
+
"@types/react": "^18.2.22",
|
20
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
21
|
+
"react": "^18.2.0"
|
20
22
|
}
|
21
23
|
}
|