diff --git a/app/web/src/render/site/mobile-loader.tsx b/app/web/src/render/site/mobile-loader.tsx new file mode 100644 index 00000000..948fbeb9 --- /dev/null +++ b/app/web/src/render/site/mobile-loader.tsx @@ -0,0 +1,55 @@ +import { w } from "../../utils/script/init-api"; +import { Loader } from "../live/logic/global"; + +const base = `/_web/${(window as any).id_site}`; + +const cache = { site: null as any, pages: [] as any, api: null }; + +export const mobileLoader: Loader = { + async site(p, id) { + const res = (await load(`/site?prod=1`)) as { + site: any; + pages: any; + api: any; + }; + cache.site = res.site; + cache.pages = res.pages; + cache.api = res.api; + + w.serverurl = res.site.config.api_url; + w.apiurl = res.site.config.api_url; + + w.prasiApi = { + [res.site.config.api_url]: { apiEntry: res.api }, + }; + + return res.site; + }, + async comp(p, id) { + const comp = (await load(`/comp/${id}`)) as any; + p.comps.all[id] = comp; + return comp; + }, + npm(p, type, id) { + if (type === "site") return `/_web/${cache.site.id}/npm-site/site.js`; + return `/_web/${cache.site.id}/npm-page/${id}/page.js`; + }, + async page(p, id) { + const page = cache.pages.find((x: any) => x.id === id); + if (page && !page.content_tree) { + const res = (await load(`/page/${id}`)) as any; + return res; + } + return null; + }, + async pages(p, id) { + return cache.pages; + }, +}; + +const load = async (url: string) => { + const res = await fetch(`${base}${url}`); + const text = await res.text(); + const json = JSON.parse(text); + return json; +}; diff --git a/app/web/src/render/site/site-loader.tsx b/app/web/src/render/site/site-loader.tsx index 6b5799f5..dddf065d 100644 --- a/app/web/src/render/site/site-loader.tsx +++ b/app/web/src/render/site/site-loader.tsx @@ -16,7 +16,6 @@ export const siteLoader: Loader = { cache.pages = res.pages; cache.api = res.api; - if (typeof w.basepath === "undefined") w.basepath = ""; w.serverurl = res.site.config.api_url; w.apiurl = res.site.config.api_url; @@ -49,8 +48,7 @@ export const siteLoader: Loader = { }; const load = async (url: string) => { - console.log("loading", `${w.basepath}${base}${url}`); - const res = await fetch(`${w.basepath}${base}${url}`); + const res = await fetch(`${base}${url}`); const text = await res.text(); const json = JSON.parse(text); return json; diff --git a/app/web/src/render/site/site.tsx b/app/web/src/render/site/site.tsx index 8cda7557..818fbc10 100644 --- a/app/web/src/render/site/site.tsx +++ b/app/web/src/render/site/site.tsx @@ -8,6 +8,7 @@ const w = window as unknown as { prasiContext: any; rootRender: any; mobile: any; + mobilepath?: any; }; if (!w.mobile) { @@ -25,7 +26,6 @@ const Root: FC<{ url: URL; Live: any }> = ({ url, Live }) => { render({}); }; - console.log(siteLoader) const Provider = GlobalContext.Provider as FC<{ value: any; children: any }>; return ( diff --git a/app/web/src/utils/script/init-api.ts b/app/web/src/utils/script/init-api.ts index e0bfff21..ecd871db 100644 --- a/app/web/src/utils/script/init-api.ts +++ b/app/web/src/utils/script/init-api.ts @@ -9,7 +9,6 @@ export const w = window as unknown as { dbClient: typeof dbClient; serverurl: string; apiurl: string; - basepath: string; }; export const createAPI = (url: string) => { diff --git a/pkgs/web-utils/src/define-window.ts b/pkgs/web-utils/src/define-window.ts index 01b6191a..5e0ac760 100644 --- a/pkgs/web-utils/src/define-window.ts +++ b/pkgs/web-utils/src/define-window.ts @@ -38,7 +38,9 @@ export const defineWindow = async (awaitServerUrl = true) => { const port = location.port; w.baseurl = scheme + "://" + host + (port ? ":" + port : "") + "/"; - w.basepath = "/"; + if (!w.basepath) { + w.basepath = "/"; + } w.css = css; w.extractCss = extractCss; w.pathname = location.pathname;