fix logout

This commit is contained in:
Rizky 2023-11-15 14:29:22 +07:00
parent df8a394d55
commit 14be1eed8d
8 changed files with 170 additions and 140 deletions

View File

@ -0,0 +1,10 @@
import { apiContext } from "service-srv";
import { session } from "utils/session";
export const _ = {
url: "/_logout",
async api() {
const { res } = apiContext(this);
res.setHeader("set-cookie", `${session.cookieKey}=X`);
},
};

View File

@ -17,6 +17,7 @@ export const codeBuild = async (code: DBCode) => {
absWorkingDir: dir.path(`${g.datadir}/site/code/${id_code}`),
entryPoints: ["index.tsx"],
bundle: true,
format: "cjs",
outfile: dir.path(`${g.datadir}/build/code/${id_code}/index.js`),
minify: true,
treeShaking: true,
@ -52,7 +53,6 @@ export const codeBuild = async (code: DBCode) => {
});
});
const result = await Code.build.ctx[id_code].rebuild();
console.log("rebuilt");
activity.site
.room(code.id_site)
.findAll({ site_js: code.name })

View File

@ -3,6 +3,7 @@ import { page, useGlobal } from "web-utils";
import { EDGlobal } from "../../render/ed/logic/ed-global";
import { edInitSync } from "../../render/ed/logic/ed-sync";
import { Loading } from "../../utils/ui/loading";
import { isLocalhost } from "../../utils/ui/is-localhost";
export default page({
url: "**",
@ -23,7 +24,11 @@ export default page({
navigate(location.pathname + "/");
}
} else {
navigate("/editor/_/_");
if (isLocalhost()) {
navigate("/ed");
} else {
navigate("/editor/_/_");
}
}
} else {
navigate("/login");

View File

@ -47,11 +47,21 @@ export default page({
form.render();
alert(s.reason);
} else {
const rto = (window as any).redirectTo;
let rto = (window as any).redirectTo;
if (rto) {
if (
location.href.includes("localhost") &&
rto.includes("/editor")
) {
rto = rto.replace("/editor", "/ed");
}
navigate(rto);
} else {
navigate("/editor");
if (location.href.includes("localhost")) {
navigate("/ed");
} else {
navigate("/editor");
}
}
}
}}

View File

@ -15,10 +15,12 @@ export default page({
}
(window as any).pathname = pathname;
navigator.serviceWorker.controller?.postMessage({
type: "add-cache",
url: location.href,
});
if (navigator.serviceWorker) {
navigator.serviceWorker.controller?.postMessage({
type: "add-cache",
url: location.href,
});
}
return (
<Live

View File

@ -17,58 +17,33 @@ const start = async () => {
};
(window as any).mobile = registerMobile();
if (!isLocalhost()) {
const sw = await registerServiceWorker();
if (navigator.serviceWorker) {
if (!isLocalhost()) {
const sw = await registerServiceWorker();
const cacheCurrentPage = () => {
const swController = navigator.serviceWorker.controller;
if (swController) {
[location.href, "", "/", "/ed", "/ed/_/_", "/login"].forEach((url) => {
swController.postMessage({
type: "add-cache",
url: url,
});
});
}
};
cacheCurrentPage();
navigator.serviceWorker.addEventListener("message", (e) => {
cacheCurrentPage();
if (react.root) {
if (e.data.type === "offline") {
w.offline = true;
const click = () => {
if (react.root) react.root.render(<Root />);
};
setTimeout(click, 5000);
react.root.render(
<>
<Root />
<div
className={cx(
css`
position: fixed;
bottom: 20px;
left: 0px;
right: 0px;
z-index: 999;
`,
"flex justify-center cursor-pointer"
)}
>
<div
className="bg-orange-500 text-white px-4 py-2 rounded-full text-sm"
onClick={click}
>
Network Failed
</div>
</div>
</>
const cacheCurrentPage = () => {
const swController = navigator.serviceWorker.controller;
if (swController) {
[location.href, "", "/", "/ed", "/ed/_/_", "/login"].forEach(
(url) => {
swController.postMessage({
type: "add-cache",
url: url,
});
}
);
}
if (e.data.type === "activated") {
if (e.data.shouldRefresh && sw) {
};
cacheCurrentPage();
navigator.serviceWorker.addEventListener("message", (e) => {
cacheCurrentPage();
if (react.root) {
if (e.data.type === "offline") {
w.offline = true;
const click = () => {
if (react.root) react.root.render(<Root />);
};
setTimeout(click, 5000);
react.root.render(
<>
<Root />
@ -81,27 +56,22 @@ const start = async () => {
right: 0px;
z-index: 999;
`,
"flex justify-center"
"flex justify-center cursor-pointer"
)}
>
<div className="bg-blue-400 text-white px-4 py-2 rounded-full text-sm">
Updating App...
<div
className="bg-orange-500 text-white px-4 py-2 rounded-full text-sm"
onClick={click}
>
Network Failed
</div>
</div>
</>
);
}
sw.unregister().then(() => {
window.location.reload();
});
} else {
const localVersion = localStorage.getItem("prasi-version");
if (localVersion !== e.data.version) {
localStorage.setItem("prasi-version", e.data.version);
const click = () => {
if (react.root) react.root.render(<Root />);
};
setTimeout(click, 5000);
if (e.data.type === "activated") {
if (e.data.shouldRefresh && sw) {
react.root.render(
<>
<Root />
@ -114,57 +84,93 @@ const start = async () => {
right: 0px;
z-index: 999;
`,
"flex justify-center cursor-pointer"
"flex justify-center"
)}
>
<div
className="bg-green-600 text-white px-4 py-2 rounded-full text-sm"
onClick={click}
>
Prasi Updated{" "}
<span className="opacity-50">{e.data.version}</span>
<div className="bg-blue-400 text-white px-4 py-2 rounded-full text-sm">
Updating App...
</div>
</div>
</>
);
sw.unregister().then(() => {
window.location.reload();
});
} else {
const localVersion = localStorage.getItem("prasi-version");
if (localVersion !== e.data.version) {
localStorage.setItem("prasi-version", e.data.version);
const click = () => {
if (react.root) react.root.render(<Root />);
};
setTimeout(click, 5000);
react.root.render(
<>
<Root />
<div
className={cx(
css`
position: fixed;
bottom: 20px;
left: 0px;
right: 0px;
z-index: 999;
`,
"flex justify-center cursor-pointer"
)}
>
<div
className="bg-green-600 text-white px-4 py-2 rounded-full text-sm"
onClick={click}
>
Prasi Updated{" "}
<span className="opacity-50">{e.data.version}</span>
</div>
</div>
</>
);
}
}
}
}
}
});
} else {
navigator.serviceWorker.getRegistrations().then(function (registrations) {
for (let registration of registrations) {
registration.unregister();
}
});
});
} else {
navigator.serviceWorker.getRegistrations().then(function (registrations) {
for (let registration of registrations) {
registration.unregister();
}
});
}
}
defineReact();
await defineWindow(false);
w.serverurl = base;
await reloadDBAPI(base, "prod");
const swc = navigator.serviceWorker.controller;
if (swc) {
[location.href, "", "/", "/ed", "/ed/_/_", "/login"].forEach((url) => {
swc.postMessage({
type: "add-cache",
url: url,
if (navigator.serviceWorker) {
const swc = navigator.serviceWorker.controller;
if (swc) {
[location.href, "", "/", "/ed", "/ed/_/_", "/login"].forEach((url) => {
swc.postMessage({
type: "add-cache",
url: url,
});
});
});
if (w.prasiApi && w.prasiApi[base] && w.prasiApi[base].apiEntry) {
const routes = Object.entries(w.prasiApi[base].apiEntry).map(
([k, v]: any) => ({
url: v.url,
name: k,
})
);
if (w.prasiApi && w.prasiApi[base] && w.prasiApi[base].apiEntry) {
const routes = Object.entries(w.prasiApi[base].apiEntry).map(
([k, v]: any) => ({
url: v.url,
name: k,
})
);
swc.postMessage({
type: "define-route",
routes,
});
swc.postMessage({
type: "define-route",
routes,
});
}
}
}
w.api = createAPI(base);

View File

@ -5,6 +5,7 @@ import { Loading } from "../../../../../utils/ui/loading";
import { Modal } from "../../../../../utils/ui/modal";
import { Tooltip } from "../../../../../utils/ui/tooltip";
import { EDGlobal } from "../../../logic/ed-global";
import { Popover } from "../../../../../utils/ui/popover";
export const EdPopCode = () => {
const p = useGlobal(EDGlobal, "EDITOR");
@ -50,50 +51,42 @@ export const EdPopCode = () => {
)}
>
<div className="border-b flex h-[40px] items-stretch">
<div
<Popover
placement="bottom"
offset={0}
arrow={false}
content={<div className="w-[200px] border">Hellow</div>}
autoFocus={false}
popoverClassName="bg-white shadow-md"
className={cx(
"flex items-center px-2 w-[200px] overflow-ellipsis space-x-1",
"cursor-pointer"
"flex items-center px-2 w-[200px] hover:bg-blue-50 space-x-1",
"cursor-pointer justify-between"
)}
>
<div className="capitalize flex-1 flex items-center justify-between">
<div>{p.ui.popup.code.name}</div>
<div className="capitalize overflow-ellipsis flex-1 flex items-center ">
{p.ui.popup.code.name}
</div>
<div
dangerouslySetInnerHTML={{
__html: `<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>`,
}}
></div>
</Popover>
{p.ui.popup.code.name !== "site" && (
<div className="hover:bg-blue-100 flex items-center justify-center border w-[20px] h-[20px] flex">
<div
dangerouslySetInnerHTML={{
__html: `<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M3.13523 6.15803C3.3241 5.95657 3.64052 5.94637 3.84197 6.13523L7.5 9.56464L11.158 6.13523C11.3595 5.94637 11.6759 5.95657 11.8648 6.15803C12.0536 6.35949 12.0434 6.67591 11.842 6.86477L7.84197 10.6148C7.64964 10.7951 7.35036 10.7951 7.15803 10.6148L3.15803 6.86477C2.95657 6.67591 2.94637 6.35949 3.13523 6.15803Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>`,
__html: `<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.07095 0.650238C6.67391 0.650238 6.32977 0.925096 6.24198 1.31231L6.0039 2.36247C5.6249 2.47269 5.26335 2.62363 4.92436 2.81013L4.01335 2.23585C3.67748 2.02413 3.23978 2.07312 2.95903 2.35386L2.35294 2.95996C2.0722 3.2407 2.0232 3.6784 2.23493 4.01427L2.80942 4.92561C2.62307 5.2645 2.47227 5.62594 2.36216 6.00481L1.31209 6.24287C0.924883 6.33065 0.650024 6.6748 0.650024 7.07183V7.92897C0.650024 8.32601 0.924883 8.67015 1.31209 8.75794L2.36228 8.99603C2.47246 9.375 2.62335 9.73652 2.80979 10.0755L2.2354 10.9867C2.02367 11.3225 2.07267 11.7602 2.35341 12.041L2.95951 12.6471C3.24025 12.9278 3.67795 12.9768 4.01382 12.7651L4.92506 12.1907C5.26384 12.377 5.62516 12.5278 6.0039 12.6379L6.24198 13.6881C6.32977 14.0753 6.67391 14.3502 7.07095 14.3502H7.92809C8.32512 14.3502 8.66927 14.0753 8.75705 13.6881L8.99505 12.6383C9.37411 12.5282 9.73573 12.3773 10.0748 12.1909L10.986 12.7653C11.3218 12.977 11.7595 12.928 12.0403 12.6473L12.6464 12.0412C12.9271 11.7604 12.9761 11.3227 12.7644 10.9869L12.1902 10.076C12.3768 9.73688 12.5278 9.37515 12.638 8.99596L13.6879 8.75794C14.0751 8.67015 14.35 8.32601 14.35 7.92897V7.07183C14.35 6.6748 14.0751 6.33065 13.6879 6.24287L12.6381 6.00488C12.528 5.62578 12.3771 5.26414 12.1906 4.92507L12.7648 4.01407C12.9766 3.6782 12.9276 3.2405 12.6468 2.95975L12.0407 2.35366C11.76 2.07292 11.3223 2.02392 10.9864 2.23565L10.0755 2.80989C9.73622 2.62328 9.37437 2.47229 8.99505 2.36209L8.75705 1.31231C8.66927 0.925096 8.32512 0.650238 7.92809 0.650238H7.07095ZM4.92053 3.81251C5.44724 3.44339 6.05665 3.18424 6.71543 3.06839L7.07095 1.50024H7.92809L8.28355 3.06816C8.94267 3.18387 9.5524 3.44302 10.0794 3.81224L11.4397 2.9547L12.0458 3.56079L11.1882 4.92117C11.5573 5.44798 11.8164 6.0575 11.9321 6.71638L13.5 7.07183V7.92897L11.932 8.28444C11.8162 8.94342 11.557 9.55301 11.1878 10.0798L12.0453 11.4402L11.4392 12.0462L10.0787 11.1886C9.55192 11.5576 8.94241 11.8166 8.28355 11.9323L7.92809 13.5002H7.07095L6.71543 11.932C6.0569 11.8162 5.44772 11.5572 4.92116 11.1883L3.56055 12.046L2.95445 11.4399L3.81213 10.0794C3.4431 9.55266 3.18403 8.94326 3.06825 8.2845L1.50002 7.92897V7.07183L3.06818 6.71632C3.18388 6.05765 3.44283 5.44833 3.81171 4.92165L2.95398 3.561L3.56008 2.95491L4.92053 3.81251ZM9.02496 7.50008C9.02496 8.34226 8.34223 9.02499 7.50005 9.02499C6.65786 9.02499 5.97513 8.34226 5.97513 7.50008C5.97513 6.65789 6.65786 5.97516 7.50005 5.97516C8.34223 5.97516 9.02496 6.65789 9.02496 7.50008ZM9.92496 7.50008C9.92496 8.83932 8.83929 9.92499 7.50005 9.92499C6.1608 9.92499 5.07513 8.83932 5.07513 7.50008C5.07513 6.16084 6.1608 5.07516 7.50005 5.07516C8.83929 5.07516 9.92496 6.16084 9.92496 7.50008Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>`,
}}
></div>
</div>
</div>
<div className="flex items-center space-x-1 border-x px-2">
{p.ui.popup.code.name !== "site" && (
<div className="hover:bg-blue-100 flex items-center justify-center border w-[20px] h-[20px] flex">
<div
dangerouslySetInnerHTML={{
__html: `<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.07095 0.650238C6.67391 0.650238 6.32977 0.925096 6.24198 1.31231L6.0039 2.36247C5.6249 2.47269 5.26335 2.62363 4.92436 2.81013L4.01335 2.23585C3.67748 2.02413 3.23978 2.07312 2.95903 2.35386L2.35294 2.95996C2.0722 3.2407 2.0232 3.6784 2.23493 4.01427L2.80942 4.92561C2.62307 5.2645 2.47227 5.62594 2.36216 6.00481L1.31209 6.24287C0.924883 6.33065 0.650024 6.6748 0.650024 7.07183V7.92897C0.650024 8.32601 0.924883 8.67015 1.31209 8.75794L2.36228 8.99603C2.47246 9.375 2.62335 9.73652 2.80979 10.0755L2.2354 10.9867C2.02367 11.3225 2.07267 11.7602 2.35341 12.041L2.95951 12.6471C3.24025 12.9278 3.67795 12.9768 4.01382 12.7651L4.92506 12.1907C5.26384 12.377 5.62516 12.5278 6.0039 12.6379L6.24198 13.6881C6.32977 14.0753 6.67391 14.3502 7.07095 14.3502H7.92809C8.32512 14.3502 8.66927 14.0753 8.75705 13.6881L8.99505 12.6383C9.37411 12.5282 9.73573 12.3773 10.0748 12.1909L10.986 12.7653C11.3218 12.977 11.7595 12.928 12.0403 12.6473L12.6464 12.0412C12.9271 11.7604 12.9761 11.3227 12.7644 10.9869L12.1902 10.076C12.3768 9.73688 12.5278 9.37515 12.638 8.99596L13.6879 8.75794C14.0751 8.67015 14.35 8.32601 14.35 7.92897V7.07183C14.35 6.6748 14.0751 6.33065 13.6879 6.24287L12.6381 6.00488C12.528 5.62578 12.3771 5.26414 12.1906 4.92507L12.7648 4.01407C12.9766 3.6782 12.9276 3.2405 12.6468 2.95975L12.0407 2.35366C11.76 2.07292 11.3223 2.02392 10.9864 2.23565L10.0755 2.80989C9.73622 2.62328 9.37437 2.47229 8.99505 2.36209L8.75705 1.31231C8.66927 0.925096 8.32512 0.650238 7.92809 0.650238H7.07095ZM4.92053 3.81251C5.44724 3.44339 6.05665 3.18424 6.71543 3.06839L7.07095 1.50024H7.92809L8.28355 3.06816C8.94267 3.18387 9.5524 3.44302 10.0794 3.81224L11.4397 2.9547L12.0458 3.56079L11.1882 4.92117C11.5573 5.44798 11.8164 6.0575 11.9321 6.71638L13.5 7.07183V7.92897L11.932 8.28444C11.8162 8.94342 11.557 9.55301 11.1878 10.0798L12.0453 11.4402L11.4392 12.0462L10.0787 11.1886C9.55192 11.5576 8.94241 11.8166 8.28355 11.9323L7.92809 13.5002H7.07095L6.71543 11.932C6.0569 11.8162 5.44772 11.5572 4.92116 11.1883L3.56055 12.046L2.95445 11.4399L3.81213 10.0794C3.4431 9.55266 3.18403 8.94326 3.06825 8.2845L1.50002 7.92897V7.07183L3.06818 6.71632C3.18388 6.05765 3.44283 5.44833 3.81171 4.92165L2.95398 3.561L3.56008 2.95491L4.92053 3.81251ZM9.02496 7.50008C9.02496 8.34226 8.34223 9.02499 7.50005 9.02499C6.65786 9.02499 5.97513 8.34226 5.97513 7.50008C5.97513 6.65789 6.65786 5.97516 7.50005 5.97516C8.34223 5.97516 9.02496 6.65789 9.02496 7.50008ZM9.92496 7.50008C9.92496 8.83932 8.83929 9.92499 7.50005 9.92499C6.1608 9.92499 5.07513 8.83932 5.07513 7.50008C5.07513 6.16084 6.1608 5.07516 7.50005 5.07516C8.83929 5.07516 9.92496 6.16084 9.92496 7.50008Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>`,
}}
></div>
</div>
)}
<Tooltip
content="New Project"
placement="bottom"
className="hover:bg-blue-100 flex items-center justify-center border w-[20px] h-[20px] flex cursor-pointer"
>
<div
dangerouslySetInnerHTML={{
__html: `<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8 2.75C8 2.47386 7.77614 2.25 7.5 2.25C7.22386 2.25 7 2.47386 7 2.75V7H2.75C2.47386 7 2.25 7.22386 2.25 7.5C2.25 7.77614 2.47386 8 2.75 8H7V12.25C7 12.5261 7.22386 12.75 7.5 12.75C7.77614 12.75 8 12.5261 8 12.25V8H12.25C12.5261 8 12.75 7.77614 12.75 7.5C12.75 7.22386 12.5261 7 12.25 7H8V2.75Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"></path></svg>`,
}}
></div>
</Tooltip>
</div>
)}
<Tooltip
content="stdout log"
delay={0}
placement="bottom"
className="flex items-stretch relative"
className="flex items-stretch relative border-l"
onClick={() => {
p.ui.popup.code.show_log = !p.ui.popup.code.show_log;
p.render();

View File

@ -1,5 +1,9 @@
export const isLocalhost = () => {
return ["localhost", "127.0.0.1", "trycloudflare.com", "ngrok"].find((e) =>
location.hostname.includes(e)
);
return [
"localhost",
"127.0.0.1",
"192.168",
"trycloudflare.com",
"ngrok",
].find((e) => location.hostname.includes(e));
};