This commit is contained in:
Rizky 2024-08-19 12:51:23 +07:00
parent fc61511170
commit c4ad06997c
3 changed files with 22 additions and 9 deletions

View File

@ -89,8 +89,8 @@ export const _ = {
const arr = pathname.split("/").slice(2);
const codepath = arr.join("/");
const build_path = code.path(site_id, "site", "build", codepath);
const build_old = code.path(site_id, "site", "build_old", codepath);
try {
let file = Bun.file(build_path);
@ -104,15 +104,29 @@ export const _ = {
}
);
} catch (e: any) {
return new Response(
`
try {
let file = Bun.file(build_old);
return new Response(
await gzipAsync(new Uint8Array(await file.arrayBuffer())),
{
headers: {
"content-encoding": "gzip",
"content-type": mime.getType(build_path) || "",
},
}
);
} catch (e) {
return new Response(
`
console.error("Failed to load index.js")
console.error("${e.message}")
`,
{
headers: { "content-type": "application/javascript" },
}
);
{
headers: { "content-type": "application/javascript" },
}
);
}
}
}
case "route": {

View File

@ -26,7 +26,7 @@ export const code = {
path(
id_site: string,
mode: "site" | "server",
type: "src" | "build" | "build_cache",
type: "src" | "build" | "build_old" | "build_cache",
path?: string
) {
let file_path = "";

View File

@ -216,7 +216,6 @@ import React from "react";
await codeError(id_site, "");
await $`mv ${out_dir} ${out_dir_old}`.quiet();
await $`mv ${out_dir_temp} ${out_dir}`.quiet();
await $`rm -rf ${out_dir_old}`.quiet();
const now = Date.now();
client_ids.forEach((client_id) => {