fix
This commit is contained in:
parent
fa3a6c1dd5
commit
a295b2ead8
|
|
@ -3,11 +3,11 @@ import { page } from "web-utils";
|
||||||
import { Loading } from "../../utils/ui/loading";
|
import { Loading } from "../../utils/ui/loading";
|
||||||
|
|
||||||
export default page({
|
export default page({
|
||||||
url: "**",
|
url: "*",
|
||||||
component: ({}) => {
|
component: ({}) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (localStorage.getItem("prasi-session")) {
|
if (localStorage.getItem("prasi-session")) {
|
||||||
navigate("/editor/_/_");
|
navigate("/editor");
|
||||||
} else {
|
} else {
|
||||||
navigate("/login");
|
navigate("/login");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export default page({
|
||||||
} else {
|
} else {
|
||||||
console.log("navigate to");
|
console.log("navigate to");
|
||||||
localStorage.setItem("prasi-session", JSON.stringify(s));
|
localStorage.setItem("prasi-session", JSON.stringify(s));
|
||||||
navigate("/editor/_/_");
|
navigate("/editor/");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
form.init = true;
|
form.init = true;
|
||||||
|
|
@ -52,7 +52,7 @@ export default page({
|
||||||
if (rto) {
|
if (rto) {
|
||||||
navigate(rto);
|
navigate(rto);
|
||||||
} else {
|
} else {
|
||||||
navigate("/editor/_/_");
|
navigate("/editor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,28 @@
|
||||||
export const all = {
|
export const auth_login = {
|
||||||
url: "**",
|
|
||||||
page: () => import("./page/all"),
|
|
||||||
};
|
|
||||||
export const login = {
|
|
||||||
url: "/login",
|
url: "/login",
|
||||||
page: () => import("./page/auth/login"),
|
page: () => import("./page/auth/login"),
|
||||||
};
|
};
|
||||||
|
export const auth_logout = {
|
||||||
|
url: "/logout",
|
||||||
|
page: () => import("./page/auth/logout"),
|
||||||
|
};
|
||||||
|
export const auth_register = {
|
||||||
|
url: "/register",
|
||||||
|
page: () => import("./page/auth/register"),
|
||||||
|
};
|
||||||
|
export const all = {
|
||||||
|
url: "*",
|
||||||
|
page: () => import("./page/all"),
|
||||||
|
};
|
||||||
|
export const ed = {
|
||||||
|
url: "/ed/:site_id/:page_id",
|
||||||
|
page: () => import("./page/ed"),
|
||||||
|
};
|
||||||
export const editor = {
|
export const editor = {
|
||||||
url: "/editor/:site_id/:page_id",
|
url: "/editor/:site_id/:page_id",
|
||||||
page: () => import("./page/editor"),
|
page: () => import("./page/editor"),
|
||||||
};
|
};
|
||||||
|
export const live = {
|
||||||
|
url: "/live/:domain/**",
|
||||||
|
page: () => import("./page/live"),
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ export const Root: FC<{}> = ({}) => {
|
||||||
const local = useLocal(
|
const local = useLocal(
|
||||||
{
|
{
|
||||||
router: createRouter<{ url: string; Page: FC<any> }>({
|
router: createRouter<{ url: string; Page: FC<any> }>({
|
||||||
strictTrailingSlash: true,
|
strictTrailingSlash: false,
|
||||||
}),
|
}),
|
||||||
Page: null as any,
|
Page: null as any,
|
||||||
},
|
},
|
||||||
|
|
@ -31,6 +31,8 @@ export const Root: FC<{}> = ({}) => {
|
||||||
const Provider = GlobalContext.Provider as FC<{ value: any; children: any }>;
|
const Provider = GlobalContext.Provider as FC<{ value: any; children: any }>;
|
||||||
|
|
||||||
const found = local.router.lookup(location.pathname);
|
const found = local.router.lookup(location.pathname);
|
||||||
|
console.log(found)
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
w.params = found.params;
|
w.params = found.params;
|
||||||
local.Page = found.Page;
|
local.Page = found.Page;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ export const editorWS = async (p: PG) => {
|
||||||
if (p.ws && p.ws.readyState === p.ws.OPEN) {
|
if (p.ws && p.ws.readyState === p.ws.OPEN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const render = () => {
|
const render = () => {
|
||||||
if (!p.focused && !p.script.active) {
|
if (!p.focused && !p.script.active) {
|
||||||
p.render();
|
p.render();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { createRouter } from "radix3";
|
||||||
import { validate } from "uuid";
|
import { validate } from "uuid";
|
||||||
import { createRouter, type apiClient } from "web-utils";
|
import { type apiClient } from "web-utils";
|
||||||
import {
|
import {
|
||||||
createAPI,
|
createAPI,
|
||||||
createDB,
|
createDB,
|
||||||
|
|
@ -9,7 +10,6 @@ import {
|
||||||
import importModule from "../../editor/tools/dynamic-import";
|
import importModule from "../../editor/tools/dynamic-import";
|
||||||
import { LSite, PG } from "./global";
|
import { LSite, PG } from "./global";
|
||||||
import { validateLayout } from "./layout";
|
import { validateLayout } from "./layout";
|
||||||
import { preload } from "./route";
|
|
||||||
|
|
||||||
export const w = window as unknown as {
|
export const w = window as unknown as {
|
||||||
basepath: string;
|
basepath: string;
|
||||||
|
|
@ -195,7 +195,7 @@ export const initLive = async (p: PG, domain: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** create router */
|
/** create router */
|
||||||
p.route = createRouter({ strictTrailingSlash: true });
|
p.route = createRouter({ strictTrailingSlash: false });
|
||||||
if (pages && pages.length > 0) {
|
if (pages && pages.length > 0) {
|
||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
p.route.insert(page.url, page);
|
p.route.insert(page.url, page);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export type WSData = { url: URL };
|
||||||
|
|
||||||
export const createServer = async () => {
|
export const createServer = async () => {
|
||||||
g.api = {};
|
g.api = {};
|
||||||
g.router = createRouter({ strictTrailingSlash: true });
|
g.router = createRouter({ strictTrailingSlash: false });
|
||||||
g.server = Bun.serve({
|
g.server = Bun.serve({
|
||||||
port: g.port,
|
port: g.port,
|
||||||
websocket: {
|
websocket: {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { file } from "bun";
|
import { file } from "bun";
|
||||||
import { watch } from "fs";
|
import { watch } from "fs";
|
||||||
|
import { dirAsync, inspectTreeAsync, readAsync, writeAsync } from "fs-jetpack";
|
||||||
|
import { dirname } from "path";
|
||||||
import { dir } from "./dir";
|
import { dir } from "./dir";
|
||||||
import { dirAsync } from "fs-jetpack";
|
const pagedir = dir.path(`app/web/src/base/page`);
|
||||||
|
|
||||||
export const startDevWatcher = async () => {
|
export const startDevWatcher = async () => {
|
||||||
await dirAsync(dir.path(`app/srv/api`));
|
await dirAsync(dir.path(`app/srv/api`));
|
||||||
|
|
@ -23,4 +25,58 @@ export const _ = {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await dirAsync(pagedir);
|
||||||
|
await genPages();
|
||||||
|
watch(pagedir, async (event, filename) => {
|
||||||
|
const s = file(dir.path(`${pagedir}/${filename}`));
|
||||||
|
if (s.size > 0) {
|
||||||
|
// await Bun.write(
|
||||||
|
// `app/srv/api/${filename}`,
|
||||||
|
// `\
|
||||||
|
// export const all = {
|
||||||
|
// url: "*",
|
||||||
|
// page: () => import("./page/all"),
|
||||||
|
// };
|
||||||
|
// `
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const genPages = async () => {
|
||||||
|
const res: string[] = [];
|
||||||
|
const walk = async (arg: any) => {
|
||||||
|
const pathname = arg.relativePath
|
||||||
|
.substring(0, arg.relativePath.length - 4)
|
||||||
|
.substring(2);
|
||||||
|
|
||||||
|
if (pathname) {
|
||||||
|
const src = await readAsync(`${pagedir}/${pathname}.tsx`);
|
||||||
|
if (src) {
|
||||||
|
const url = src.split("url:")[1].split(",").shift();
|
||||||
|
if (url) {
|
||||||
|
res.push(
|
||||||
|
`\
|
||||||
|
export const ${pathname.replace(/\W/gi, "_")} = {
|
||||||
|
url: ${url},
|
||||||
|
page: () => import("./page/${pathname}"),
|
||||||
|
};`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.children) {
|
||||||
|
for (const c of arg.children) {
|
||||||
|
await walk(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await walk(
|
||||||
|
await inspectTreeAsync(pagedir, {
|
||||||
|
relativePath: true,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
await writeAsync(dirname(pagedir) + "/pages.ts", `${res.join("\n")}\n`);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue