wip fix
This commit is contained in:
parent
49dd18c0b0
commit
7d76160943
|
|
@ -5,6 +5,7 @@ import path from "path";
|
|||
import { gzipAsync } from "../ws/sync/entity/zlib";
|
||||
import { validate } from "uuid";
|
||||
import { dir } from "dir";
|
||||
import { existsAsync, readAsync } from "fs-jetpack";
|
||||
|
||||
export const _ = {
|
||||
url: "/prod-zip/:site_id",
|
||||
|
|
@ -43,16 +44,30 @@ export const _ = {
|
|||
},
|
||||
select: { id: true, content_tree: true },
|
||||
}),
|
||||
site: await _db.component.findFirst({ where: { id: site_id } }),
|
||||
site: await _db.site.findFirst({
|
||||
where: { id: site_id },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
config: true,
|
||||
responsive: true,
|
||||
domain: true,
|
||||
},
|
||||
}),
|
||||
code: {
|
||||
server: readDirectoryRecursively(
|
||||
code.path(site_id, "server", "build")
|
||||
),
|
||||
site: readDirectoryRecursively(code.path(site_id, "site", "build")),
|
||||
core: readDirectoryRecursively(dir.data(`prod`)),
|
||||
core: readDirectoryRecursively(dir.path(`/app/srv/prod`)),
|
||||
},
|
||||
};
|
||||
|
||||
if (await existsAsync(dir.path("/app/static/index.css"))) {
|
||||
result.code.site["index.css"] =
|
||||
(await readAsync(dir.path("/app/static/index.css"))) || "";
|
||||
}
|
||||
|
||||
return await gzipAsync(JSON.stringify(result));
|
||||
}
|
||||
return new Response("NOT FOUND", { status: 403 });
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ export const _ = {
|
|||
} else if (pathname === "index.html" || pathname === "_") {
|
||||
return index_html;
|
||||
} else {
|
||||
const res = dir.data(`/prod/${pathname}`);
|
||||
const res = dir.path(`/app/srv/prod/${pathname}`);
|
||||
const file = Bun.file(res);
|
||||
if (!(await file.exists())) {
|
||||
return index_html;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,6 @@
|
|||
import trim from "lodash.trim";
|
||||
import { w } from "../../../utils/types/general";
|
||||
import { fetchViaProxy } from "../proxy";
|
||||
import { compress } from "wasm-gzip";
|
||||
|
||||
export const loadApiProxyDef = async (_url: string, with_types: boolean) => {
|
||||
const url = trim(_url, "/");
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@ export const apiProxy = (api_url: string) => {
|
|||
let base_url = `${base.protocol}//${base.host}`;
|
||||
if (!w.prasiApi[base_url]) {
|
||||
if (!apiProxyLoaded[base_url]) {
|
||||
apiProxyLoaded[base_url] = loadApiProxyDef(base_url, true);
|
||||
apiProxyLoaded[base_url] = loadApiProxyDef(
|
||||
base_url,
|
||||
location.hostname.includes("prasi")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,15 @@ export const base = {
|
|||
const pathname = arg
|
||||
.map((e) => (Array.isArray(e) ? e.join("") : e))
|
||||
.join("");
|
||||
if (pathname.startsWith("/")) return this.root + pathname;
|
||||
else return this.root.toString() + "/" + pathname;
|
||||
|
||||
let base_url = this.root.toString();
|
||||
if (base_url.endsWith("/"))
|
||||
base_url = base_url.substring(0, base_url.length - 1);
|
||||
|
||||
if (pathname.startsWith("/")) return base_url + pathname;
|
||||
else {
|
||||
return base_url + "/" + pathname;
|
||||
}
|
||||
},
|
||||
get pathname() {
|
||||
return location.pathname.substring(base.root.pathname.length);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ const getRoute = () => {
|
|||
}
|
||||
|
||||
let raw = await (await fetch(base.url`_prasi/route`)).blob();
|
||||
const res = JSON.parse(await (await decompressBlob(raw)).text());
|
||||
const dc = decompressBlob(raw);
|
||||
const unziped = await dc;
|
||||
const res = JSON.parse(await unziped.text());
|
||||
|
||||
await set("route", res, prodCache);
|
||||
if (!is_done) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,9 @@ export const Root = () => {
|
|||
|
||||
const site_script = evalCJS(
|
||||
await (
|
||||
await fetch(`/prod/${base.site.id}/_prasi/code/index.js`)
|
||||
await fetch(
|
||||
`${w._prasi.basepath}/_prasi/code/index.js`.replace("//", "/")
|
||||
)
|
||||
).text()
|
||||
);
|
||||
if (site_script) {
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ export const w = window as unknown as {
|
|||
};
|
||||
params: any;
|
||||
navigateOverride: (href: string) => void;
|
||||
_prasi: { basepath: string };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const ctx = await context({
|
|||
bundle: true,
|
||||
absWorkingDir: dir.path(""),
|
||||
entryPoints: [dir.path("app/web/src/nova/prod/main.tsx")],
|
||||
outdir: dir.data(`/prod`),
|
||||
outdir: dir.path(`/app/srv/prod`),
|
||||
splitting: true,
|
||||
format: "esm",
|
||||
jsx: "transform",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import { preparePrisma } from "./utils/prisma";
|
|||
|
||||
g.status = "init";
|
||||
|
||||
|
||||
await writeAsync(
|
||||
dir.path("app/web/timestamp.ts"),
|
||||
`export const version = "${createId().substring(0, 7)}";`
|
||||
|
|
@ -76,8 +75,6 @@ if (!g.parcel) {
|
|||
await parcelBuild();
|
||||
}
|
||||
|
||||
await import("./build-prod");
|
||||
|
||||
const { createServer } = await import("./server/create");
|
||||
await createServer();
|
||||
g.status = "ready";
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ if (!g.dockerPrepared) {
|
|||
},
|
||||
};
|
||||
|
||||
await import("./core/build-prod");
|
||||
|
||||
if (!(await existsAsync(dir.path("_tmp_docker")))) {
|
||||
for (const file of Object.keys(dir.read(dir.path``))) {
|
||||
if (
|
||||
|
|
|
|||
Loading…
Reference in New Issue