@aklinker1/aframe 0.2.1 → 0.2.3
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 +20 -0
- package/package.json +1 -1
- package/src/client/server.ts +10 -3
- package/src/config.ts +1 -1
package/README.md
CHANGED
|
@@ -106,3 +106,23 @@ When importing a file as text, like an HTML template or a `.gql` schema, you sho
|
|
|
106
106
|
// server/main.ts
|
|
107
107
|
import welcomeEmailTemplate from "./assets/email-templates/welcome.html" with { type: "text" };
|
|
108
108
|
```
|
|
109
|
+
|
|
110
|
+
## Detecting Prerender
|
|
111
|
+
|
|
112
|
+
When prerendering, the page is loaded with the `?prerendering` query param.
|
|
113
|
+
|
|
114
|
+
Aframe provides a helper for checking this, `isPrerendering`:
|
|
115
|
+
|
|
116
|
+
```vue
|
|
117
|
+
<!-- ClientOnly.vue -->
|
|
118
|
+
<script setup lang="ts">
|
|
119
|
+
import { isPrerendering } from "@aklinker1/aframe/app";
|
|
120
|
+
|
|
121
|
+
const visible = !isPrerendering();
|
|
122
|
+
</script>
|
|
123
|
+
|
|
124
|
+
<template>
|
|
125
|
+
<slot v-if="visible" />
|
|
126
|
+
<slot v-else name="fallback" />
|
|
127
|
+
</template>
|
|
128
|
+
```
|
package/package.json
CHANGED
package/src/client/server.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { BunFile } from "bun";
|
|
2
2
|
|
|
3
|
+
const headers = {
|
|
4
|
+
"Cache-Control": "max-age=31536000",
|
|
5
|
+
};
|
|
6
|
+
|
|
3
7
|
export interface AframeServer {
|
|
4
8
|
listen(port: number): void | never;
|
|
5
9
|
}
|
|
@@ -12,10 +16,10 @@ export async function fetchStatic(request: Request): Promise<Response> {
|
|
|
12
16
|
if (!path) return fetchRootHtml();
|
|
13
17
|
|
|
14
18
|
const exactFile = Bun.file(`${import.meta.publicDir}${path}`);
|
|
15
|
-
if (await isFile(exactFile)) return new Response(exactFile);
|
|
19
|
+
if (await isFile(exactFile)) return new Response(exactFile, { headers });
|
|
16
20
|
|
|
17
21
|
const htmlFile = Bun.file(`${import.meta.publicDir}${path}/index.html`);
|
|
18
|
-
if (await isFile(htmlFile)) return new Response(exactFile);
|
|
22
|
+
if (await isFile(htmlFile)) return new Response(exactFile, { headers });
|
|
19
23
|
|
|
20
24
|
return fetchRootHtml();
|
|
21
25
|
}
|
|
@@ -33,12 +37,15 @@ function fetchRootHtml() {
|
|
|
33
37
|
{
|
|
34
38
|
headers: {
|
|
35
39
|
"Content-Type": "text/html",
|
|
40
|
+
...headers,
|
|
36
41
|
},
|
|
37
42
|
},
|
|
38
43
|
);
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
return new Response(Bun.file(`${import.meta.publicDir}/index.html`)
|
|
46
|
+
return new Response(Bun.file(`${import.meta.publicDir}/index.html`), {
|
|
47
|
+
headers,
|
|
48
|
+
});
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
async function isFile(file: BunFile): Promise<boolean> {
|
package/src/config.ts
CHANGED