@aklinker1/aframe 0.2.3 → 0.2.4
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/package.json +1 -1
- package/src/client/server.ts +37 -28
- package/src/index.ts +2 -1
package/package.json
CHANGED
package/src/client/server.ts
CHANGED
|
@@ -8,44 +8,53 @@ export interface AframeServer {
|
|
|
8
8
|
listen(port: number): void | never;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
const cache: Record<string, BunFile> = {};
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* Fetches a file from the `public` directory.
|
|
13
15
|
*/
|
|
14
16
|
export async function fetchStatic(request: Request): Promise<Response> {
|
|
15
17
|
const path = new URL(request.url).pathname.replace(/\/+$/, "");
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
const exactFile = Bun.file(`${import.meta.publicDir}${path}`);
|
|
19
|
-
if (await isFile(exactFile)) return new Response(exactFile, { headers });
|
|
18
|
+
if (cache[path]) return new Response(cache[path], { headers });
|
|
20
19
|
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
20
|
+
const paths = [
|
|
21
|
+
`${import.meta.publicDir}${path}.gz`,
|
|
22
|
+
`${import.meta.publicDir}${path}`,
|
|
23
|
+
`${import.meta.publicDir}${path}/index.html.gz`,
|
|
24
|
+
`${import.meta.publicDir}${path}/index.html`,
|
|
25
|
+
];
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
if (import.meta.command === "
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
This is a placeholder for your root <code>index.html</code> file during development.
|
|
33
|
-
<br/>
|
|
34
|
-
In production (or via the app's dev server), this path will fallback on the root <code>index.html</code>.
|
|
35
|
-
</body>
|
|
36
|
-
</html>`,
|
|
37
|
-
{
|
|
38
|
-
headers: {
|
|
39
|
-
"Content-Type": "text/html",
|
|
40
|
-
...headers,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
27
|
+
// Only fallback on the root HTML file when building application
|
|
28
|
+
if (import.meta.command === "build") {
|
|
29
|
+
paths.push(
|
|
30
|
+
`${import.meta.publicDir}/index.html.gz`,
|
|
31
|
+
`${import.meta.publicDir}/index.html`,
|
|
43
32
|
);
|
|
44
33
|
}
|
|
45
34
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
for (const path of paths) {
|
|
36
|
+
const file = Bun.file(path);
|
|
37
|
+
if (await isFile(file)) {
|
|
38
|
+
cache[path] = file;
|
|
39
|
+
return new Response(file, { headers });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return new Response(
|
|
44
|
+
`<html>
|
|
45
|
+
<body>
|
|
46
|
+
This is a placeholder for your root <code>index.html</code> file during development.
|
|
47
|
+
<br/>
|
|
48
|
+
In production (or via the app's dev server), this path will fallback on the root <code>index.html</code>.
|
|
49
|
+
</body>
|
|
50
|
+
</html>`,
|
|
51
|
+
{
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "text/html",
|
|
54
|
+
...headers,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
);
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
async function isFile(file: BunFile): Promise<boolean> {
|
package/src/index.ts
CHANGED
|
@@ -138,7 +138,8 @@ function getColor(file: string) {
|
|
|
138
138
|
if (file.endsWith(".js")) return CYAN;
|
|
139
139
|
if (file.endsWith(".html")) return GREEN;
|
|
140
140
|
if (file.endsWith(".css")) return MAGENTA;
|
|
141
|
-
if (file.endsWith(".
|
|
141
|
+
if (file.endsWith(".map")) return DIM;
|
|
142
|
+
if (file.endsWith(".gz")) return DIM;
|
|
142
143
|
return BLUE;
|
|
143
144
|
}
|
|
144
145
|
|