@aklinker1/aframe 0.2.5 → 0.3.0

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/README.md CHANGED
@@ -13,6 +13,7 @@ Simple wrapper around Vite for creating pre-rendered, client-side web apps with
13
13
  📁 public/
14
14
  📄 favicon.ico
15
15
  📁 server/
16
+ 📄 env.d.ts
16
17
  📄 main.ts
17
18
  📄 .env
18
19
  📄 aframe.config.ts
@@ -34,6 +35,11 @@ export default defineConfig({
34
35
  });
35
36
  ```
36
37
 
38
+ ```ts
39
+ // server/env.d.ts
40
+ /// <reference types="@aklinker1/aframe/env" />
41
+ ```
42
+
37
43
  ```ts
38
44
  // server/main.ts
39
45
  import { Elysia } from "elysia";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aklinker1/aframe",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "packageManager": "bun@1.2.2",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -11,53 +11,67 @@ export interface AframeServer {
11
11
  /**
12
12
  * Fetches a file from the `public` directory.
13
13
  */
14
- export async function fetchStatic(request: Request): Promise<Response> {
15
- const path = new URL(request.url).pathname.replace(/\/+$/, "");
14
+ export function fetchStatic(options?: {
15
+ /** Override the fetch behavior of a file. */
16
+ onFetch?: (
17
+ path: string,
18
+ file: BunFile,
19
+ ) => Promise<Response | undefined> | Response | undefined;
20
+ }): (request: Request) => Promise<Response> {
21
+ return async (request) => {
22
+ const path = new URL(request.url).pathname.replace(/\/+$/, "");
16
23
 
17
- const paths = [
18
- `${import.meta.publicDir}${path}`,
19
- `${import.meta.publicDir}${path}/index.html`,
20
- ];
24
+ const paths = [
25
+ `${import.meta.publicDir}${path}`,
26
+ `${import.meta.publicDir}${path}/index.html`,
27
+ ];
21
28
 
22
- // Only fallback on the root HTML file when building application
23
- if (import.meta.command === "build") {
24
- paths.push(`${import.meta.publicDir}/index.html`);
25
- }
29
+ // Only fallback on the root HTML file when building application
30
+ if (import.meta.command === "build") {
31
+ paths.push(`${import.meta.publicDir}/index.html`);
32
+ }
26
33
 
27
- for (const path of paths) {
28
- const gzFile = Bun.file(path + ".gz");
29
- const file = Bun.file(path);
34
+ for (const path of paths) {
35
+ const isHtml = path.includes(".html");
36
+ const gzFile = Bun.file(path + ".gz");
37
+ const file = Bun.file(path);
30
38
 
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
- }
39
+ if (await isFile(gzFile)) {
40
+ const customResponse = await options?.onFetch?.(path, file);
41
+ if (customResponse) return customResponse;
42
+ return new Response(gzFile.stream(), {
43
+ headers: {
44
+ ...(isHtml ? {} : headers),
45
+ "content-type": file.type,
46
+ "content-encoding": "gzip",
47
+ },
48
+ });
49
+ }
40
50
 
41
- if (await isFile(file)) {
42
- return new Response(file.stream(), { headers });
51
+ if (await isFile(file)) {
52
+ const customResponse = await options?.onFetch?.(path, file);
53
+ if (customResponse) return customResponse;
54
+
55
+ return new Response(file.stream(), { headers });
56
+ }
43
57
  }
44
- }
45
58
 
46
- return new Response(
47
- `<html>
48
- <body>
49
- This is a placeholder for your root <code>index.html</code> file during development.
50
- <br/>
51
- In production (or via the app's dev server), this path will fallback on the root <code>index.html</code>.
52
- </body>
53
- </html>`,
54
- {
55
- headers: {
56
- "Content-Type": "text/html",
57
- ...headers,
59
+ return new Response(
60
+ `<html>
61
+ <body>
62
+ This is a placeholder for your root <code>index.html</code> file during development.
63
+ <br/>
64
+ In production (or via the app's dev server), this path will fallback on the root <code>index.html</code>.
65
+ </body>
66
+ </html>`,
67
+ {
68
+ headers: {
69
+ "Content-Type": "text/html",
70
+ ...headers,
71
+ },
58
72
  },
59
- },
60
- );
73
+ );
74
+ };
61
75
  }
62
76
 
63
77
  async function isFile(file: BunFile): Promise<boolean> {