diff --git a/app/srv/api/prod.ts b/app/srv/api/prod.ts index 69d08b7b..268f3004 100644 --- a/app/srv/api/prod.ts +++ b/app/srv/api/prod.ts @@ -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": { diff --git a/app/srv/ws/sync/code/code.ts b/app/srv/ws/sync/code/code.ts index f65b026b..0367e763 100644 --- a/app/srv/ws/sync/code/code.ts +++ b/app/srv/ws/sync/code/code.ts @@ -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 = ""; diff --git a/app/srv/ws/sync/code/parts/init/frontend.ts b/app/srv/ws/sync/code/parts/init/frontend.ts index 444f1aeb..c8a875ed 100644 --- a/app/srv/ws/sync/code/parts/init/frontend.ts +++ b/app/srv/ws/sync/code/parts/init/frontend.ts @@ -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) => {