Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
fix the issue once and for all, minor imporvements
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed Apr 6, 2024
1 parent 223580b commit 36be4d2
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 57 deletions.
25 changes: 6 additions & 19 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createServer } from "node:http";
import { createServer as createViteServer } from "vite";
import express from "express";
import path from "path";
import cors from "cors";
import compression from "compression";
import { argv } from "node:process";
import { Socket } from "node:net";
Expand Down Expand Up @@ -31,11 +30,6 @@ const vite = await createViteServer({
server: { middlewareMode: true },
});
const app = express();
const corsOptions = {
origin: `*`,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true,
};
const compressionOptions = {
threshold: 0,
filter: () => true,
Expand All @@ -44,21 +38,13 @@ const masqr =
(process.env.MASQR && process.env.MASQR.toLowerCase() === "true") ||
usingMasqr;
app.use(compression(compressionOptions));
app.use(cors(corsOptions));
if (!devMode) {
app.use(express.static("dist"));
} else {
app.use(vite.middlewares);
}
if (!devMode) {
app.get("*", (_, response) => {
response.sendFile(path.resolve("dist", "index.html"));
});
}
app.use(express.static("dist"));
app.get("*", (_, response) => {
response.sendFile(path.resolve("dist", "index.html"));
});

const server = createServer();
server.on("request", app);

server.on("request", devMode ? vite.middlewares : app);
server.on("upgrade", (req, socket: Socket, head) => {
if (req.url.endsWith("/wisp/")) {
wisp.routeRequest(req, socket, head);
Expand All @@ -69,3 +55,4 @@ console.log(`
\x1b[34;49;1m[Ephemeral] \x1B[32mINFO: Running on port ${port} in ${devMode ? "dev" : "production"} mode
Configured with Masqr: ${masqr}
`);
vite.bindCLIShortcuts({ print: true });
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"clsx": "^2.1.0",
"cmdk": "^0.2.1",
"compression": "^1.7.4",
"cors": "^2.8.5",
"crypto-js": "^4.2.0",
"embla-carousel-react": "^8.0.1",
"eruda": "^3.0.1",
Expand Down
11 changes: 0 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/shortcut-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function ShortcutCard({ app }: { app: Application }) {
res.blob().then((blob) => URL.createObjectURL(blob) as string),
),
);
}, [app, run]);
}, [app]); // eslint-disable-line
return (
<Link to={`/view/${encoder.encode(app.url)}`}>
<Card className="my-2 flex h-[19rem] w-72 flex-col items-center justify-center duration-200 hover:bg-secondary">
Expand Down
12 changes: 6 additions & 6 deletions src/pages/apps.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Fuse from "fuse.js";

import { For } from "million/react";
import { Input } from "@/components/ui/input";
import ShortcutCard from "@/components/shortcut-card";
import { useState, useEffect, useRef } from "react";
Expand Down Expand Up @@ -67,11 +67,11 @@ export default function Apps() {
ref={listRef}
className="3xl:grid-cols-6 4xl:grid-cols-7 grid grid-cols-1 place-content-center place-items-center p-8 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5"
>
{searchResults
? searchResults.map((app, key) => (
<ShortcutCard app={app} key={key} />
))
: null}
{searchResults ? (
<For each={searchResults} memo>
{(app, index) => <ShortcutCard app={app} key={index} />}
</For>
) : null}
</div>
<span
className={`flex w-full items-center justify-center pb-10 text-center text-2xl font-bold ${error ? "text-red-600" : "text-foreground"}`}
Expand Down
2 changes: 0 additions & 2 deletions src/pages/settings/proxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default function ProxySettings() {
if (wispServerRef.current)
config && (config.wispServer = wispServerRef.current?.value);
unregisterServiceWorker();
localStorage.setItem("refreshAgain", "true");
toast({
title: "Proxy Settings have been saved",
});
Expand All @@ -45,7 +44,6 @@ export default function ProxySettings() {
const handleReset = () => {
reset();
unregisterServiceWorker();
localStorage.setItem("refreshAgain", "true");
toast({
title: "Proxy Settings have been reset",
variant: "destructive",
Expand Down
13 changes: 4 additions & 9 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const routes = createBrowserRouter([
]);
export default function AppRoutes() {
const [init, setInit] = useState(false);
const [swRegistered, setSwRegistered] = useState(false);
const [config] = useConfig("proxy");
useEffect(() => {
if ("serviceWorker" in navigator) {
Expand All @@ -60,17 +61,10 @@ export default function AppRoutes() {
scope: "/~/",
})
.then(() => {
if (
localStorage.getItem("refreshAgain") === "true" ||
!localStorage.getItem("firstLoad")
) {
localStorage.removeItem("refreshAgain");
localStorage.setItem("firstLoad", "true");
window.location.reload();
}
console.log(
"\x1b[34;49;1m[Ephemeral] \x1B[32mINFO: Service workers registered",
);
setSwRegistered(true);
})
.catch((err) => {
console.error(
Expand All @@ -86,6 +80,7 @@ export default function AppRoutes() {
}, []);
useEffect(() => {
try {
if (!swRegistered) return;
BareMux.registerRemoteListener(navigator.serviceWorker.controller!);
BareMux.SetTransport(transports[config.transport], {
wisp: config.wispServer,
Expand All @@ -97,6 +92,6 @@ export default function AppRoutes() {
} catch (e) {
console.error(e);
}
}, [config, init]);
}, [config, init, swRegistered]);
return init ? <RouterProvider router={routes} /> : null;
}
8 changes: 0 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ export default defineConfig({
dest: "uv",
overwrite: false,
},
{
src: `${__dirname}/node_modules/localforage/dist/localforage.*.js`.replace(
/\\/g,
"/",
),
dest: "localforage",
overwrite: false,
},
{
src: `${libcurlPath}/**/*`.replace(/\\/g, "/"),
dest: "libcurl",
Expand Down

0 comments on commit 36be4d2

Please sign in to comment.