wip fix safari
This commit is contained in:
parent
d274636ff9
commit
3dc13caab8
|
|
@ -0,0 +1 @@
|
|||
export const apiClient = (base: string) => {};
|
||||
|
|
@ -15,6 +15,8 @@ const start = async () => {
|
|||
};
|
||||
w.mobile = registerMobile();
|
||||
w.db = dbClient("prasi", location.origin);
|
||||
w.serverurl = base;
|
||||
|
||||
sworkerRegister(react);
|
||||
defineReact();
|
||||
await defineWindow(false);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { createAPI, initApi } from "../../../../../utils/script/init-api";
|
||||
import { PG } from "../../../logic/ed-global";
|
||||
|
||||
export const dev = JSON.parse(localStorage.getItem("prasi-dev") || "{}") as {
|
||||
|
|
@ -51,8 +50,8 @@ export const checkAPI = async (p: PG) => {
|
|||
|
||||
try {
|
||||
if (!apiRef[url]) {
|
||||
await initApi({ api_url: url }, "dev");
|
||||
apiRef[url] = createAPI(url);
|
||||
// await initApi({ api_url: url }, "dev");
|
||||
// apiRef[url] = createAPI(url);
|
||||
}
|
||||
const capi = apiRef[url];
|
||||
let res = await capi._deploy({
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import importModule from "../../../render/editor/tools/dynamic-import";
|
||||
import { initApi } from "../../../utils/script/init-api";
|
||||
import { viScriptArg } from "../render/script/arg";
|
||||
|
||||
export const viLoadLegacy = async (vi: {
|
||||
site: {
|
||||
|
|
@ -38,7 +38,7 @@ export const viLoadLegacy = async (vi: {
|
|||
let api_url = vi.site.api_url;
|
||||
if (!api_url) api_url = ((site.config as any) || {}).api_url || "";
|
||||
|
||||
await initApi(site.config);
|
||||
// await initApi(site.config);
|
||||
|
||||
const path = `/npm/site/${vi.site.id}/site.js`;
|
||||
await importModule(path);
|
||||
|
|
@ -62,6 +62,7 @@ export const viLoadLegacy = async (vi: {
|
|||
return res;
|
||||
};
|
||||
const scope = {
|
||||
...viScriptArg(),
|
||||
types: {},
|
||||
exports: w.exports,
|
||||
load: importModule,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { syncActionDefinition } from "utils/sync-def";
|
|||
import { user } from "../../app/srv/ws/sync/entity/user";
|
||||
import { snapshot } from "../../app/srv/ws/sync/entity/snapshot";
|
||||
import { initSrv } from "../../app/srv/init";
|
||||
import { prepareApiRoutes } from "./server/api/api-scan";
|
||||
|
||||
g.status = "init";
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ if (!g.apiPrepared) {
|
|||
await initSrv();
|
||||
await syncActionDefinition();
|
||||
g.log.info("WS Action defined");
|
||||
|
||||
await prepareApiRoutes();
|
||||
await prepareAPITypes();
|
||||
g.log.info("API Prepared");
|
||||
g.apiPrepared = true;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,10 @@ export const createServer = async () => {
|
|||
return serveStatic.serve(url);
|
||||
}
|
||||
|
||||
await serveAPI.serve(url, req);
|
||||
const api_response = await serveAPI.serve(url, req);
|
||||
if (api_response) {
|
||||
return api_response;
|
||||
}
|
||||
|
||||
return serveStatic.serve(url);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ export const serveAPI = {
|
|||
for (const route of Object.values(g.api)) {
|
||||
g.router.insert(route.url.replace(/\*/gi, "**"), route);
|
||||
}
|
||||
await prepareApiRoutes();
|
||||
},
|
||||
serve: async (url: URL, req: Request) => {
|
||||
let found = g.router.lookup(url.pathname);
|
||||
|
|
@ -81,6 +80,7 @@ export const serveAPI = {
|
|||
if (finalResponse) {
|
||||
return createResponse(current.res, finalResponse);
|
||||
}
|
||||
|
||||
if (
|
||||
(current.res as any)._status &&
|
||||
(current.res as any)._status !== current.res.status
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ import { dir } from "dir";
|
|||
import { inspectTreeAsync } from "fs-jetpack";
|
||||
import { InspectTreeResult } from "fs-jetpack/types";
|
||||
import { join } from "path";
|
||||
import { watch } from "fs";
|
||||
|
||||
import mime from "mime";
|
||||
import { g } from "utils/global";
|
||||
|
||||
const webPath = "app/static";
|
||||
const cache = {
|
||||
|
|
@ -16,27 +19,40 @@ export const serveStatic = {
|
|||
list: InspectTreeResult,
|
||||
parent?: InspectTreeResult[]
|
||||
) => {
|
||||
for (const item of list.children) {
|
||||
if (item.type === "file") {
|
||||
const path = join(
|
||||
...(parent || [{ name: "static" }]).map((e) => e.name),
|
||||
item.name
|
||||
);
|
||||
const file = await Bun.file(dir.path(`app/${path}`));
|
||||
if (await file.exists()) {
|
||||
cache.static[path.substring("static".length)] = {
|
||||
type: mime.getType(path) || "application/octet-stream",
|
||||
content: await file.arrayBuffer(),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
await walk(item, parent ? [...parent, list] : [list]);
|
||||
if (list.type === "dir") {
|
||||
for (const item of list.children) {
|
||||
await walk(item, [...(parent || []), list]);
|
||||
}
|
||||
} else {
|
||||
const path = join(...(parent || []).map((e) => e.name), list.name);
|
||||
const file = Bun.file(dir.path(`app/${path}`));
|
||||
if (await file.exists()) {
|
||||
cache.static[path.substring("static".length)] = {
|
||||
type: mime.getType(path) || "application/octet-stream",
|
||||
content: await file.arrayBuffer(),
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
if (list) {
|
||||
await walk(list);
|
||||
}
|
||||
|
||||
if (g.mode === "dev") {
|
||||
watch(dir.path(`app/static`), async (_, filename) => {
|
||||
if (filename) {
|
||||
const path = join("static", filename);
|
||||
const file = Bun.file(dir.path(`app/${path}`));
|
||||
console.log(_, filename);
|
||||
if (await file.exists()) {
|
||||
cache.static[`/${filename}`] = {
|
||||
type: mime.getType(path) || "application/octet-stream",
|
||||
content: await file.arrayBuffer(),
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
exists: (url: URL) => {
|
||||
return !!cache.static[url.pathname];
|
||||
|
|
|
|||
Loading…
Reference in New Issue