diff --git a/backend/database/src/index.ts b/backend/database/src/index.ts index a116e01..9831589 100644 --- a/backend/database/src/index.ts +++ b/backend/database/src/index.ts @@ -237,7 +237,9 @@ export default { const res = await db.query.user.findFirst({ where: (user, { eq }) => eq(user.id, id), with: { - sandbox: true, + sandbox: { + orderBy: (sandbox, { desc }) => [desc(sandbox.createdAt)], + }, usersToSandboxes: true, }, }); diff --git a/backend/server/dockerfile b/backend/server/dockerfile index cc82df0..c027747 100644 --- a/backend/server/dockerfile +++ b/backend/server/dockerfile @@ -16,13 +16,13 @@ COPY . . RUN npm run build # Security: Create non-root user and assign ownership -RUN useradd -m sboxuser -RUN mkdir projects && chown -R sboxuser:sboxuser projects -USER sboxuser +RUN useradd -m appuser +RUN mkdir projects && chown -R appuser:appuser projects +USER appuser -# user namespace mapping +# todo user namespace mapping -EXPOSE 8000 -EXPOSE 5173 +EXPOSE 3000 +EXPOSE 4000 CMD [ "node", "dist/index.js" ] \ No newline at end of file diff --git a/backend/server/src/index.ts b/backend/server/src/index.ts index a1c98b8..8485889 100644 --- a/backend/server/src/index.ts +++ b/backend/server/src/index.ts @@ -51,19 +51,21 @@ const terminals: { const dirName = path.join(__dirname, ".."); -const handshakeSchema = z.object({ - userId: z.string(), - sandboxId: z.string(), - EIO: z.string(), - transport: z.string(), -}); - io.use(async (socket, next) => { + console.log("Middleware"); + + const handshakeSchema = z.object({ + userId: z.string(), + sandboxId: z.string(), + EIO: z.string(), + transport: z.string(), + }); + const q = socket.handshake.query; const parseQuery = handshakeSchema.safeParse(q); if (!parseQuery.success) { - ("Invalid request."); + console.log("Invalid request."); next(new Error("Invalid request.")); return; } @@ -75,6 +77,7 @@ io.use(async (socket, next) => { const dbUserJSON = (await dbUser.json()) as User; if (!dbUserJSON) { + console.log("DB error."); next(new Error("DB error.")); return; } @@ -85,6 +88,7 @@ io.use(async (socket, next) => { ); if (!sandbox && !sharedSandboxes) { + console.log("Invalid credentials."); next(new Error("Invalid credentials.")); return; } @@ -145,6 +149,7 @@ io.on("connection", async (socket) => { // todo: send diffs + debounce for efficiency socket.on("saveFile", async (fileId: string, body: string) => { + console.log("save"); try { await saveFileRL.consume(data.userId, 1); @@ -470,5 +475,5 @@ io.on("connection", async (socket) => { }); httpServer.listen(port, () => { - console.log(`Server, running on port ${port}`); + console.log(`Server 123, running on port ${port}`); }); diff --git a/backend/storage/src/startercode.ts b/backend/storage/src/startercode.ts index 495bbfb..5049eef 100644 --- a/backend/storage/src/startercode.ts +++ b/backend/storage/src/startercode.ts @@ -56,8 +56,9 @@ import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], server: { - port: 8000, - }, + port: 3000, + host: "0.0.0.0", + } }) `, }, @@ -87,10 +88,12 @@ export default defineConfig({ flex-direction: column; align-items: center; justify-content: center; + + font-family: sans-serif; } h1 { - color: #fff; + color: #000; margin: 0; } diff --git a/frontend/components/editor/editor.tsx b/frontend/components/editor/editor.tsx index e76d42a..1cfc8c9 100644 --- a/frontend/components/editor/editor.tsx +++ b/frontend/components/editor/editor.tsx @@ -90,10 +90,6 @@ export default function CodeEditor({ terminal: Terminal | null; }[] >([]); - const [activeTerminalId, setActiveTerminalId] = useState(""); - const [creatingTerminal, setCreatingTerminal] = useState(false); - const [closingTerminal, setClosingTerminal] = useState(""); - const activeTerminal = terminals.find((t) => t.id === activeTerminalId); const isOwner = sandboxData.userId === userData.id; const clerk = useClerk(); @@ -752,14 +748,7 @@ export default function CodeEditor({ ) : (
diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index 32426a1..25b37fd 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -34,55 +34,50 @@ export default function Editor({ return; } - // startServer(sandboxData.id).then((response) => { - // if (!response.success) { - // toast.error(response.message); - // setDidFail(true); - // } else { - // setIsServiceRunning(true); + startServer(sandboxData.id).then((response) => { + if (!response.success) { + toast.error(response.message); + setDidFail(true); + } else { + setIsServiceRunning(true); - // checkServiceStatus(sandboxData.id) - // .then(() => { - // setIsDeploymentActive(true); + checkServiceStatus(sandboxData.id) + .then(() => { + setIsDeploymentActive(true); - // getTaskIp(sandboxData.id) - // .then((ip) => { - // setTaskIp(ip); - // }) - // .catch(() => { - // setDidFail(true); - // toast.error("An error occurred while getting your server IP."); - // }); - // }) - // .catch(() => { - // toast.error("An error occurred while initializing your server."); - // setDidFail(true); - // }); - // } - // }); + getTaskIp(sandboxData.id) + .then((ip) => { + setTaskIp(ip); + }) + .catch(() => { + setDidFail(true); + toast.error("An error occurred while getting your server IP."); + }); + }) + .catch(() => { + toast.error("An error occurred while initializing your server."); + setDidFail(true); + }); + } + }); }, []); - // if (didFail) return ; - // if (!isServiceRunning || !isDeploymentActive || !taskIp) - // return ( - // - // ); + if (didFail) return ; + if (!isServiceRunning || !isDeploymentActive || !taskIp) + return ( + + ); return ( - + ); } diff --git a/frontend/components/editor/preview/index.tsx b/frontend/components/editor/preview/index.tsx index 7eb6f49..4df92a4 100644 --- a/frontend/components/editor/preview/index.tsx +++ b/frontend/components/editor/preview/index.tsx @@ -9,7 +9,7 @@ import { TerminalSquare, UnfoldVertical, } from "lucide-react"; -import { useRef } from "react"; +import { useRef, useState } from "react"; import { toast } from "sonner"; export default function PreviewWindow({ @@ -22,6 +22,7 @@ export default function PreviewWindow({ ip: string; }) { const ref = useRef(null); + const [iframeKey, setIframeKey] = useState(0); return ( <> @@ -33,9 +34,9 @@ export default function PreviewWindow({
Preview - + {/* localhost:8000 - + */}
{collapsed ? ( @@ -45,13 +46,13 @@ export default function PreviewWindow({ ) : ( <> {/* Todo, make this open inspector */} - {}}> + {/* {}}> - + */} { - navigator.clipboard.writeText(`http://${ip}:8000`); + navigator.clipboard.writeText(`http://${ip}:3000`); toast.info("Copied preview link to clipboard"); }} > @@ -59,9 +60,10 @@ export default function PreviewWindow({ { - if (ref.current) { - ref.current.contentWindow?.location.reload(); - } + // if (ref.current) { + // ref.current.contentWindow?.location.reload(); + // } + setIframeKey((prev) => prev + 1); }} > @@ -74,10 +76,11 @@ export default function PreviewWindow({ {collapsed ? null : (