flowrix 1.0.1-beta.8 → 1.0.1-beta.9
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/dist/module.json +1 -1
- package/dist/module.mjs +9 -1
- package/dist/runtime/composables/Header/useHeader.d.ts +1 -1
- package/dist/runtime/plugins/fullReload.client.d.ts +2 -0
- package/dist/runtime/plugins/fullReload.client.js +10 -0
- package/dist/runtime/utils/htmlCache.d.ts +5 -0
- package/dist/runtime/utils/htmlCache.js +54 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, installModule,
|
|
1
|
+
import { defineNuxtModule, createResolver, installModule, addServerHandler, addPlugin, addImportsDir, addImports } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const module = defineNuxtModule({
|
|
4
4
|
meta: {
|
|
@@ -27,6 +27,14 @@ const module = defineNuxtModule({
|
|
|
27
27
|
};
|
|
28
28
|
const resolver = createResolver(import.meta.url);
|
|
29
29
|
await installModule("@pinia/nuxt");
|
|
30
|
+
addServerHandler({
|
|
31
|
+
middleware: true,
|
|
32
|
+
handler: resolver.resolve("./runtime/utils/htmlCache")
|
|
33
|
+
});
|
|
34
|
+
addPlugin({
|
|
35
|
+
src: resolver.resolve("./runtime/plugins/fullReload.client"),
|
|
36
|
+
mode: "client"
|
|
37
|
+
});
|
|
30
38
|
addImportsDir(resolver.resolve("./runtime/stores"));
|
|
31
39
|
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
32
40
|
addPlugin({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default function (): {
|
|
2
|
-
NavMenu: import("pinia").Store<"NavMenu", import("
|
|
2
|
+
NavMenu: import("pinia").Store<"NavMenu", import("#imports").NavMenuState, {}, {
|
|
3
3
|
navMenu(id: number, location?: string): Promise<void>;
|
|
4
4
|
}>;
|
|
5
5
|
companyProfile: import("vue").ComputedRef<null>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function readCache(pathname: string): Promise<string | null>;
|
|
2
|
+
export declare function writeCache(pathname: string, html: string): Promise<void>;
|
|
3
|
+
export declare function clearCache(): Promise<void>;
|
|
4
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string | undefined>>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { getRequestURL } from "h3";
|
|
4
|
+
import { defineEventHandler } from "h3";
|
|
5
|
+
const cacheDir = join(process.cwd(), ".nuxt", "cache", "html");
|
|
6
|
+
async function ensureDir() {
|
|
7
|
+
await fs.mkdir(cacheDir, { recursive: true });
|
|
8
|
+
}
|
|
9
|
+
function getCacheFilePath(pathname) {
|
|
10
|
+
const safeName = pathname.replace(/[\/\\:?<>|"]/g, "_") || "index";
|
|
11
|
+
return join(cacheDir, `${safeName}.html`);
|
|
12
|
+
}
|
|
13
|
+
export async function readCache(pathname) {
|
|
14
|
+
try {
|
|
15
|
+
const filePath = getCacheFilePath(pathname);
|
|
16
|
+
const html = await fs.readFile(filePath, "utf8");
|
|
17
|
+
return html;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export async function writeCache(pathname, html) {
|
|
23
|
+
await ensureDir();
|
|
24
|
+
const filePath = getCacheFilePath(pathname);
|
|
25
|
+
await fs.writeFile(filePath, html, "utf8");
|
|
26
|
+
}
|
|
27
|
+
export async function clearCache() {
|
|
28
|
+
try {
|
|
29
|
+
await fs.rm(cacheDir, { recursive: true, force: true });
|
|
30
|
+
await ensureDir();
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export default defineEventHandler(async (event) => {
|
|
35
|
+
const url = getRequestURL(event);
|
|
36
|
+
const pathname = url.pathname;
|
|
37
|
+
if (event.method !== "GET" || !event.headers.get("accept")?.includes("text/html")) return;
|
|
38
|
+
const cached = await readCache(pathname);
|
|
39
|
+
if (cached) {
|
|
40
|
+
event.node.res.setHeader("x-cache", "HIT");
|
|
41
|
+
return cached;
|
|
42
|
+
}
|
|
43
|
+
const originalEnd = event.node.res.end;
|
|
44
|
+
let chunks = [];
|
|
45
|
+
event.node.res.end = function(chunk) {
|
|
46
|
+
if (chunk) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
47
|
+
const html = Buffer.concat(chunks).toString("utf-8");
|
|
48
|
+
if (event.node.res.statusCode === 200 && html.includes("<!DOCTYPE html>")) {
|
|
49
|
+
writeCache(pathname, html);
|
|
50
|
+
}
|
|
51
|
+
return originalEnd.apply(this, arguments);
|
|
52
|
+
};
|
|
53
|
+
return;
|
|
54
|
+
});
|