Skip to content

Commit

Permalink
funi
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed Jun 29, 2024
1 parent d2ce3d6 commit f447809
Show file tree
Hide file tree
Showing 13 changed files with 488 additions and 442 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
86 changes: 42 additions & 44 deletions server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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}`);
});
36 changes: 20 additions & 16 deletions src/app/auth/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -24,21 +25,24 @@ export default async function Login({
</Alert>
) : null}
<div className="mx-auto mt-4 flex w-full flex-col items-center justify-center gap-2">
{providersArray.map((provider) => (
<form
key={provider}
className="w-full"
action={async () => {
"use server";
await signIn(provider);
}}
>
<StyledSubmit className="my-1 w-full">
<LogIn className="mr-2 size-4" />
Log in with {provider.charAt(0).toUpperCase() + provider.slice(1)}
</StyledSubmit>
</form>
))}
{providersArray.map((provider) => {
const { Icon } = providers[provider];
return (
<form
key={provider}
className="w-full"
action={async () => {
"use server";
await signIn(provider);
}}
>
<StyledSubmit className="my-1 w-full">
<Icon className="mr-2 size-4" />
Log in with {provider.charAt(0).toUpperCase() + provider.slice(1)}
</StyledSubmit>
</form>
);
})}
</div>
</CardContent>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/auth/logout/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default function SignOut() {
<form
action={async () => {
"use server";
await signOut();
redirect("/");
await signOut({ redirect: false });
redirect("/auth/login");
}}
>
<StyledSubmit className="mt-6 w-full">
Expand Down
45 changes: 45 additions & 0 deletions src/components/icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { SVGProps } from "react";
export const GitHubIcon = (props: SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" {...props}>
<title>{"GitHub"}</title>
<path d="M5.884 18.653c-.3-.2-.558-.455-.86-.816a50.59 50.59 0 0 1-.466-.579c-.463-.575-.755-.841-1.056-.95a1 1 0 1 1 .675-1.882c.752.27 1.261.735 1.947 1.588-.094-.117.34.427.433.539.19.227.33.365.44.438.204.137.588.196 1.15.14.024-.382.094-.753.202-1.095-2.968-.726-4.648-2.64-4.648-6.396 0-1.24.37-2.356 1.058-3.292-.218-.894-.185-1.975.302-3.192a1 1 0 0 1 .63-.582c.081-.024.127-.035.208-.047.803-.124 1.937.17 3.415 1.096a11.73 11.73 0 0 1 2.687-.308c.912 0 1.819.104 2.684.308 1.477-.933 2.614-1.227 3.422-1.096.085.013.158.03.218.05a1 1 0 0 1 .616.58c.487 1.216.52 2.296.302 3.19.691.936 1.058 2.045 1.058 3.293 0 3.757-1.674 5.665-4.642 6.392.125.415.19.878.19 1.38 0 .665-.002 1.299-.007 2.01 0 .19-.002.394-.005.706a1 1 0 0 1-.018 1.958c-1.14.227-1.984-.532-1.984-1.525l.002-.447.005-.705c.005-.707.008-1.337.008-1.997 0-.697-.184-1.152-.426-1.361-.661-.57-.326-1.654.541-1.751 2.966-.333 4.336-1.482 4.336-4.66 0-.955-.312-1.744-.913-2.404A1 1 0 0 1 17.2 6.19c.166-.414.236-.957.095-1.614l-.01.003c-.491.139-1.11.44-1.858.949a1 1 0 0 1-.833.135 9.626 9.626 0 0 0-2.592-.349c-.89 0-1.772.118-2.592.35a1 1 0 0 1-.829-.134c-.753-.507-1.374-.807-1.87-.947-.143.653-.072 1.194.093 1.607a1 1 0 0 1-.189 1.045c-.597.655-.913 1.458-.913 2.404 0 3.172 1.371 4.328 4.322 4.66.865.097 1.202 1.177.545 1.748-.193.168-.43.732-.43 1.364v3.15c0 .985-.834 1.725-1.96 1.528a1 1 0 0 1-.04-1.962v-.99c-.91.061-1.661-.088-2.254-.485Z" />
</svg>
);
export const DiscordIcon = (props: SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 24 24" {...props}>
<title>Discord</title>
<path
className="fill-current"
d="M8.52062 13.8456C7.48059 13.8456 6.63159 12.9011 6.63159 11.7444 6.63159 10.5876 7.45936 9.64307 8.52062 9.64307 9.57123 9.64307 10.4308 10.5876 10.4096 11.7444 10.4096 12.9011 9.57123 13.8456 8.52062 13.8456ZM15.4941 13.8456C14.454 13.8456 13.604 12.9011 13.604 11.7444 13.604 10.5876 14.4328 9.64307 15.4941 9.64307 16.5447 9.64307 17.4043 10.5876 17.3831 11.7444 17.3831 12.9011 16.5553 13.8456 15.4941 13.8456ZM10.1253 4.32272 9.81655 3.75977 9.18323 3.86532C7.71915 4.10934 6.32658 4.54652 5.02544 5.1458L4.79651 5.25124 4.65507 5.45985C2.0418 9.31417 1.3258 13.1084 1.68032 16.836L1.71897 17.2423 2.04912 17.4822C3.78851 18.7463 5.47417 19.5186 7.12727 20.0254L7.91657 20.2674 9.03013 17.5504C10.9397 18.0224 13.0592 18.0225 14.969 17.5508L16.0757 20.2681 16.8668 20.0254C18.5173 19.5191 20.2137 18.7469 21.9466 17.4809L22.2726 17.2428 22.3131 16.8412C22.7491 12.521 21.616 8.75749 19.3547 5.45628L19.2128 5.2492 18.9846 5.1448C17.6767 4.5466 16.2852 4.10957 14.8309 3.86549L14.2132 3.76182 13.8987 4.30344C13.8112 4.4542 13.7215 4.6244 13.6364 4.79662 12.5441 4.68445 11.456 4.68421 10.3726 4.79627 10.2882 4.62711 10.2025 4.46356 10.1253 4.32272ZM6.71436 16.61C6.91235 16.724 7.11973 16.8356 7.32557 16.9378L6.8764 18.0338C5.75585 17.6256 4.61837 17.0635 3.4476 16.2555 3.22313 13.1175 3.86092 9.95075 6.01196 6.68602 6.90962 6.29099 7.8535 5.98255 8.83606 5.77271 8.89631 5.89807 8.95235 6.02042 8.99839 6.12892L9.27128 6.77213 9.96259 6.67074C11.3152 6.47235 12.6772 6.47209 14.0523 6.671L14.7424 6.77082 15.0147 6.12892C15.0621 6.01719 15.1167 5.89523 15.1743 5.77298 16.1525 5.98301 17.098 6.29188 18.0029 6.68787 19.8781 9.50833 20.8241 12.6541 20.5486 16.255 19.3837 17.0623 18.2422 17.6246 17.1193 18.0333L16.6735 16.9387C16.8799 16.8362 17.0879 16.7243 17.2865 16.61 17.7763 16.3277 18.3039 15.9757 18.6402 15.6395L17.3606 14.36C17.1969 14.5237 16.837 14.7805 16.3831 15.0421 15.9388 15.2981 15.498 15.5049 15.2164 15.598 13.2126 16.2606 10.7883 16.2606 8.78443 15.598 8.50285 15.5049 8.06205 15.2981 7.61772 15.0421 7.16383 14.7805 6.80392 14.5237 6.64017 14.36L5.36065 15.6395C5.6969 15.9757 6.2245 16.3277 6.71436 16.61Z"
/>
</svg>
);
export const GoogleIcon = (props: SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" {...props}>
<title>Google</title>
<path d="M3.064 7.51A9.996 9.996 0 0 1 12 2c2.695 0 4.959.991 6.69 2.605l-2.867 2.868C14.786 6.482 13.468 5.977 12 5.977c-2.605 0-4.81 1.76-5.595 4.123-.2.6-.314 1.24-.314 1.9 0 .66.114 1.3.314 1.9.786 2.364 2.99 4.123 5.595 4.123 1.345 0 2.49-.355 3.386-.955a4.6 4.6 0 0 0 1.996-3.018H12v-3.868h9.418c.118.654.182 1.336.182 2.045 0 3.046-1.09 5.61-2.982 7.35C16.964 21.105 14.7 22 12 22A9.996 9.996 0 0 1 2 12c0-1.614.386-3.14 1.064-4.49Z" />
</svg>
);
export const GitLabIcon = (props: SVGProps<SVGSVGElement>) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={24}
height={24}
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
className="lucide lucide-gitlab"
{...props}
>
<title>GitLab</title>
<path d="m22 13.29-3.33-10a.42.42 0 0 0-.14-.18.38.38 0 0 0-.22-.11.39.39 0 0 0-.23.07.42.42 0 0 0-.14.18l-2.26 6.67H8.32L6.1 3.26a.42.42 0 0 0-.1-.18.38.38 0 0 0-.26-.08.39.39 0 0 0-.23.07.42.42 0 0 0-.14.18L2 13.29a.74.74 0 0 0 .27.83L12 21l9.69-6.88a.71.71 0 0 0 .31-.83Z" />
</svg>
);
export const AppleIcon = (props: SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" {...props}>
<title>Apple</title>
<path d="M15.778 8.208c-.473-.037-.98.076-1.758.373.065-.025-.742.29-.969.37-.502.175-.915.271-1.378.271-.458 0-.88-.092-1.365-.255-.156-.053-.312-.11-.505-.186l-.449-.177c-.648-.254-1.012-.35-1.315-.342-1.153.014-2.243.68-2.877 1.782-1.292 2.243-.576 6.299 1.313 9.031 1.005 1.444 1.556 1.96 1.777 1.953.222-.01.386-.057.784-.225l.166-.071c1.006-.429 1.71-.618 2.771-.618 1.021 0 1.703.186 2.669.602l.168.072c.397.17.54.208.792.202.357-.005.798-.417 1.777-1.854.268-.391.505-.803.71-1.22a7.375 7.375 0 0 1-.391-.347c-1.29-1.228-2.087-2.884-2.109-4.93A6.625 6.625 0 0 1 17 8.458a4.124 4.124 0 0 0-1.221-.25Zm.155-1.994c.708.048 2.736.264 4.056 2.196-.108.06-2.424 1.404-2.4 4.212.036 3.36 2.94 4.476 2.976 4.488-.024.084-.468 1.596-1.536 3.156-.924 1.356-1.884 2.7-3.396 2.724-1.488.036-1.968-.876-3.66-.876-1.704 0-2.232.852-3.636.912-1.464.048-2.568-1.464-3.504-2.808-1.908-2.76-3.36-7.776-1.404-11.172.972-1.692 2.7-2.76 4.584-2.784 1.428-.036 2.784.96 3.66.96.864 0 2.412-1.152 4.26-1.008Zm-1.14-1.824c-.78.936-2.052 1.668-3.288 1.572-.168-1.272.456-2.604 1.176-3.432.804-.936 2.148-1.632 3.264-1.68.144 1.296-.372 2.604-1.152 3.54Z" />
</svg>
);
Loading

0 comments on commit f447809

Please sign in to comment.