wip checkpoint

This commit is contained in:
Rizky 2023-12-16 17:12:02 +07:00
parent 6ddbd121cb
commit 9e0c895c37
6 changed files with 27 additions and 26 deletions

View File

@ -1,7 +1,8 @@
import hash_sum from "hash-sum"; import hash_sum from "hash-sum";
import { fetchViaProxy } from "../proxy"; import { fetchViaProxy } from "../../../nova/vi/load/proxy";
export const dbClient = (name: string, dburl: string) => { export const dbClient = (name: string, dburl: string) => {
console.log(dburl);
return new Proxy( return new Proxy(
{}, {},
{ {

View File

@ -7,19 +7,6 @@ import { Loading } from "../../utils/ui/loading";
export default page({ export default page({
url: "/ed/:site_id/:page_id", url: "/ed/:site_id/:page_id",
component: ({}) => { component: ({}) => {
console.log("momoka");
setTimeout(() => {
(async () => {
console.log(
await fetch("/moka", {
method: "POST",
body: "{}",
})
);
})();
}, 2000);
return <>uwuw</>;
const p = useGlobal(EDGlobal, "EDITOR"); const p = useGlobal(EDGlobal, "EDITOR");
const w = window as any; const w = window as any;

View File

@ -6,6 +6,7 @@ import { registerMobile } from "./render/live/logic/mobile";
import { reloadDBAPI } from "./utils/script/init-api"; import { reloadDBAPI } from "./utils/script/init-api";
import { w } from "./utils/types/general"; import { w } from "./utils/types/general";
import { sworkerAddCache, sworkerRegister } from "./sworker-boot"; import { sworkerAddCache, sworkerRegister } from "./sworker-boot";
import { dbClient } from "./base/load/db/client-db";
const start = async () => { const start = async () => {
const base = `${location.protocol}//${location.host}`; const base = `${location.protocol}//${location.host}`;
@ -13,12 +14,11 @@ const start = async () => {
root: null as null | ReactRoot, root: null as null | ReactRoot,
}; };
w.mobile = registerMobile(); w.mobile = registerMobile();
w.db = dbClient("prasi", location.origin);
// sworkerRegister(react); sworkerRegister(react);
defineReact(); defineReact();
await defineWindow(false); await defineWindow(false);
// await reloadDBAPI(base, "prod"); sworkerAddCache(base);
// sworkerAddCache(base);
const el = document.getElementById("root"); const el = document.getElementById("root");

View File

@ -1,6 +1,6 @@
import init from "wasm-gzip"; import init from "wasm-gzip";
import { jscript } from "../../../utils/script/jscript"; import { jscript } from "../../../utils/script/jscript";
import { dbClient } from "../../vi/load/db/client-db"; import { dbClient } from "../../../base/load/db/client-db";
import { PG } from "./ed-global"; import { PG } from "./ed-global";
import { fetchViaProxy } from "../../vi/load/proxy"; import { fetchViaProxy } from "../../vi/load/proxy";

View File

@ -1,8 +1,7 @@
import { createRouter } from "radix3";
import { g } from "../utils/global"; import { g } from "../utils/global";
import { serveWS } from "./serve-ws";
import { serveStatic } from "./serve-static";
import { serveAPI } from "./serve-api"; import { serveAPI } from "./serve-api";
import { serveStatic } from "./serve-static";
import { serveWS } from "./serve-ws";
export const cache = { export const cache = {
static: {} as Record< static: {} as Record<
@ -20,15 +19,29 @@ export type WSData = { url: URL };
export const createServer = async () => { export const createServer = async () => {
await serveAPI.init(); await serveAPI.init();
await serveStatic.init(); await serveStatic.init();
const { wsHandler } = await import("../../../app/srv/ws/handler");
g.server = Bun.serve({ g.server = Bun.serve({
port: g.port, port: g.port,
maxRequestBodySize: 9999999, maxRequestBodySize: 9999999,
development: true, development: true,
websocket: await serveWS(), websocket: await serveWS(wsHandler),
async fetch(req, server) { async fetch(req, server) {
const url = new URL(req.url); const url = new URL(req.url);
if (wsHandler[url.pathname]) {
if (
server.upgrade(req, {
data: {
url: new URL(req.url),
},
})
) {
return;
}
return new Response("Upgrade failed :(", { status: 500 });
}
if (serveStatic.exists(url)) { if (serveStatic.exists(url)) {
return serveStatic.serve(url); return serveStatic.serve(url);
} }

View File

@ -1,9 +1,9 @@
import { WebSocketHandler } from "bun"; import { WebSocketHandler } from "bun";
import { WSData } from "./create"; import { WSData } from "./create";
export const serveWS: () => Promise<WebSocketHandler<WSData>> = async () => { export const serveWS: (
const { wsHandler } = await import("../../../app/srv/ws/handler"); wsHandler: Record<string, WebSocketHandler<WSData>>
) => Promise<WebSocketHandler<WSData>> = async (wsHandler) => {
return { return {
maxPayloadLength: 9999999, maxPayloadLength: 9999999,
closeOnBackpressureLimit: true, closeOnBackpressureLimit: true,