diff --git a/.env.example b/.env.example index 85cae55..b81f8da 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,8 @@ DOCKER_TYPE=socket DOCKER_SOCKET=/var/run/docker.sock # docker port - for http connection DOCKER_PORT= +# docker network used for connecting to containers +DOCKER_NETWORK= # Primary Domain for showing description - for SEO. Leave empty unless you know what you are doing METADATA_URL= # Auth providers - comma separated list of providers diff --git a/package.json b/package.json index 3cb0d28..6ee96cc 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "build": "next build", "start": "NODE_ENV=production tsx server.ts", "lint": "biome lint --apply .", + "check": "biome check --apply .", "format": "biome format --write .", "drizzle-kit": "drizzle-kit", "db:push": "drizzle-kit push" diff --git a/server.ts b/server.ts index 3ff209a..3d2c407 100644 --- a/server.ts +++ b/server.ts @@ -9,7 +9,7 @@ import { WebSocketServer } from "ws"; const port = Number.parseInt(process.env.PORT as string) || 3000; const dev = process.env.NODE_ENV !== "production"; if (process.argv.includes("--turbo")) { - process.env.TURBOPACK = "1"; + process.env.TURBOPACK = "1"; } const server = createServer(); const app = next({ dev, port, httpServer: server, hostname: process.env.HOSTNAME }); @@ -19,55 +19,53 @@ const nextRequest = app.getRequestHandler(); const nextUpgrade = app.getUpgradeHandler(); const websockify = new WebSocketServer({ noServer: true }); websockify.on("connection", async (ws, req) => { - try { - const id = req.url?.split("/")[2]; - if (!id) { - ws.close(1008, "Missing ID"); - return; - } - const container = await docker.getContainer(id).inspect(); - const ip = container.NetworkSettings.Networks[container.HostConfig.NetworkMode as string].IPAddress; - const socket = new Socket(); - socket.connect(5901, ip); - ws.on("message", (message: Uint8Array) => { - socket.write(message); - }); - ws.on("close", (code, reason) => { - consola.info( - `✨ Stardust: Connection closed with code ${code} and ${ - reason.toString() ? `reason ${reason.toString()}` : "no reason" - }`, - ); - socket.end(); - }); + try { + const id = req.url?.split("/")[2]; + if (!id) { + ws.close(1008, "Missing ID"); + return; + } + const ip = (await docker.getContainer(id).inspect()).NetworkSettings.Networks[process.env.DOCKER_NETWORK as string].IPAddress + const socket = new Socket(); + socket.connect(5901, ip); + ws.on("message", (message: Uint8Array) => { + socket.write(message); + }); + ws.on("close", (code, reason) => { + consola.info( + `✨ Stardust: Connection closed with code ${code} and ${reason.toString() ? `reason ${reason.toString()}` : "no reason" + }`, + ); + socket.end(); + }); - socket.on("data", (data) => { - ws.send(data); - }); + socket.on("data", (data) => { + ws.send(data); + }); - socket.on("error", (err) => { - consola.warn(`✨ Stardust: ${err.message}`); - ws.close(); - }); + socket.on("error", (err) => { + consola.warn(`✨ Stardust: ${err.message}`); + ws.close(); + }); - socket.on("close", () => { - ws.close(); - }); - } catch (error) { - ws.close(1008, "Server error"); - consola.error(`✨ Stardust: ${(error as Error).message}`); - } + socket.on("close", () => { + ws.close(); + }); + } catch (error) { + ws.close(1008, "Server error"); + consola.error(`✨ Stardust: ${(error as Error).message}`); + } }); server.on("request", nextRequest); server.on("upgrade", async (req, socket, head) => { - if (req.url?.includes("websockify")) { - websockify.handleUpgrade(req, socket, head, (ws) => { - websockify.emit("connection", ws, req, websockify); - }); - } else { - nextUpgrade(req, socket, head); - } + if (req.url?.includes("websockify")) { + websockify.handleUpgrade(req, socket, head, (ws) => { + websockify.emit("connection", ws, req, websockify); + }); + } else { + nextUpgrade(req, socket, head); + } }); server.listen(port, () => { - consola.success(`✨ Stardust: Server listening on ${port}`); + consola.success(`✨ Stardust: Server listening on ${port}`); }); diff --git a/src/app/auth/login/page.tsx b/src/app/auth/login/page.tsx index 7a0bd2f..7410d97 100644 --- a/src/app/auth/login/page.tsx +++ b/src/app/auth/login/page.tsx @@ -2,7 +2,8 @@ import { StyledSubmit } from "@/components/submit-button"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { CardContent } from "@/components/ui/card"; import { auth, signIn } from "@/lib/auth"; -import { AlertCircle, LogIn } from "lucide-react"; +import { providers } from "@/lib/auth.config"; +import { AlertCircle } from "lucide-react"; import { redirect } from "next/navigation"; export default async function Login({ @@ -24,21 +25,24 @@ export default async function Login({ ) : null}