@aklinker1/aframe 0.2.4 → 0.2.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aklinker1/aframe",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "packageManager": "bun@1.2.2",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,35 +8,38 @@ export interface AframeServer {
8
8
  listen(port: number): void | never;
9
9
  }
10
10
 
11
- const cache: Record<string, BunFile> = {};
12
-
13
11
  /**
14
12
  * Fetches a file from the `public` directory.
15
13
  */
16
14
  export async function fetchStatic(request: Request): Promise<Response> {
17
15
  const path = new URL(request.url).pathname.replace(/\/+$/, "");
18
- if (cache[path]) return new Response(cache[path], { headers });
19
16
 
20
17
  const paths = [
21
- `${import.meta.publicDir}${path}.gz`,
22
18
  `${import.meta.publicDir}${path}`,
23
- `${import.meta.publicDir}${path}/index.html.gz`,
24
19
  `${import.meta.publicDir}${path}/index.html`,
25
20
  ];
26
21
 
27
22
  // Only fallback on the root HTML file when building application
28
23
  if (import.meta.command === "build") {
29
- paths.push(
30
- `${import.meta.publicDir}/index.html.gz`,
31
- `${import.meta.publicDir}/index.html`,
32
- );
24
+ paths.push(`${import.meta.publicDir}/index.html`);
33
25
  }
34
26
 
35
27
  for (const path of paths) {
28
+ const gzFile = Bun.file(path + ".gz");
36
29
  const file = Bun.file(path);
30
+
31
+ if (await isFile(gzFile)) {
32
+ return new Response(gzFile.stream(), {
33
+ headers: {
34
+ ...headers,
35
+ "content-type": file.type,
36
+ "content-encoding": "gzip",
37
+ },
38
+ });
39
+ }
40
+
37
41
  if (await isFile(file)) {
38
- cache[path] = file;
39
- return new Response(file, { headers });
42
+ return new Response(file.stream(), { headers });
40
43
  }
41
44
  }
42
45