Skip to content

Commit

Permalink
refactor: fix weirdness on view page error handling, update to next c…
Browse files Browse the repository at this point in the history
…znary
  • Loading branch information
IncognitoTGT committed Feb 14, 2025
1 parent 839340d commit fef32c7
Show file tree
Hide file tree
Showing 10 changed files with 481 additions and 418 deletions.
1 change: 1 addition & 0 deletions apps/web/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const nextConfig: NextConfig = {
webpackBuildWorker: true,
reactCompiler: true,
authInterrupts: true,
newDevOverlay: true,
serverActions: {
allowedOrigins: ["localhost:3000", "*.use.devtunnels.ms"],
},
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"clsx": "^2.1.1",
"geist": "^1.3.1",
"lucide-react": "^0.460.0",
"next": "15.1.6",
"next": "15.2.0-canary.57",
"next-themes": "^0.4.4",
"postcss": "^8.4.49",
"react": "19.0.0-rc-66855b96-20241106",
Expand Down
8 changes: 3 additions & 5 deletions apps/web/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ if (!validateConfig(config)) {
const dev = process.env.NODE_ENV !== "production";
const port = config.port || 3000;
const hostname = config.hostname || "0.0.0.0";
console.log(
`✨ Stardust: Starting ${dev ? "development" : "production"} server ${process.argv.includes("--turbo") ? "with turbopack" : ""}...`,
);
console.log(`✨ Stardust: Starting ${dev ? "development" : "production"} server...`);
const httpServer = createServer();
const app = next({
dev,
port,
httpServer,
customServer: true,
hostname: process.env.HOSTNAME,
turbopack: process.argv.includes("--turbo"),
turbopack: true,
customServer: true,
});
await app.prepare();
scheduleAutoDelete();
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/api/session/[slug]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { NextRequest } from "next/server";

export async function GET(_req: NextRequest, props: { params: Promise<{ slug: string }> }) {
const params = await props.params;
const session = await getSession(params.slug);
const session = await getSession(params.slug).catch(() => {});
if (!session) {
return Response.json({ exists: false, error: "Container not found" }, { status: 404 });
}
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/app/view/[slug]/components.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AlertCircle, Info, Loader2 } from "lucide-react";
import { Info, Loader2 } from "lucide-react";

export function Loading({ text }: { text: string }) {
return (
Expand All @@ -9,10 +9,10 @@ export function Loading({ text }: { text: string }) {
);
}
export function ConnectionAlert({ text, error }: { text: string; error?: boolean }) {
const Comp = error ? AlertCircle : Info;
if (error) throw new Error(text);
return (
<div className="h-40 w-96 bg-accent/50 rounded-lg border border-border/50 absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 backdrop-blur-md flex items-center justify-center text-muted-foreground gap-3">
<Comp className={`${error && "text-destructive"}`} />
<Info className={`${error && "text-destructive"}`} />
<h1 className="text-2xl font-semibold">{text}</h1>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/view/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export default function Page(props: { params: Promise<{ slug: string }> }) {
className="absolute z-20 h-screen w-screen overflow-clip"
/>
) : (
<ConnectionAlert text="Container not running" />
<ConnectionAlert error text="Session not found" />
)
) : (
<Loading text="Authenticating" />
Expand Down
57 changes: 28 additions & 29 deletions apps/web/src/lib/session/best-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,32 @@ import { getConfig } from "@stardust/config";
import type { NodeConfig } from "@stardust/config/config";

export async function getBestNode(workspace: string) {
const { nodes: configNodes } = getConfig();
const nodes: Record<number, number> = {};
const availableNodes = (
await Promise.all(
configNodes.map(async (n) => {
const { data } = await stardustConnector(n).workspaces.index.get();
if (!data) throw new Error("No node data");
return {
id: n.id,
workspaces: data.workspaces.map((w) => w.RepoTags[0]?.split(":")[0]),
};
}),
)
)
.filter((n) => n.workspaces.includes(workspace))
.map((d) => d.id);
if (availableNodes.length <= 0) throw new Error("No node with the selected workspace found");
await Promise.all(
configNodes
.filter(({ id }) => availableNodes.includes(id))
.map(async (n: NodeConfig, i) => {
const { data } = await stardustConnector(n).healthcheck.get();
nodes[i] = Number(data?.cpu);
}),
);
console.log(nodes);
return Object.keys(nodes)
.map(Number)
.find((key) => nodes[key] === Math.min(...Object.values(nodes))) as number; // shoot me
const { nodes: configNodes } = getConfig();
const nodes: Record<number, number> = {};
const availableNodes = (
await Promise.all(
configNodes.map(async (n) => {
const { data } = await stardustConnector(n).workspaces.index.get();
if (!data) throw new Error("No node data");
return {
id: n.id,
workspaces: data.workspaces.map((w) => w.RepoTags[0]?.split(":")[0]),
};
}),
)
)
.filter((n) => n.workspaces.includes(workspace))
.map((d) => d.id);
if (availableNodes.length <= 0) throw new Error("No node with the selected workspace found");
await Promise.all(
configNodes
.filter(({ id }) => availableNodes.includes(id))
.map(async (n: NodeConfig, i) => {
const { data } = await stardustConnector(n).healthcheck.get();
nodes[i] = Number(data?.cpu);
}),
);
return Object.keys(nodes)
.map(Number)
.find((key) => nodes[key] === Math.min(...Object.values(nodes))) as number; // shoot me
}
46 changes: 23 additions & 23 deletions apps/web/src/lib/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { getConfig } from "@stardust/config";
import db, { workspace } from "@stardust/db";

export async function getWorkspaces() {
const { nodes } = getConfig();
return await Promise.all(
(await db.select().from(workspace)).map(async (w) => {
const nodeMetadata = await Promise.all(
nodes.map(async (n) => {
const { data } = await stardustConnector(n).workspaces.index.get();
if (!data) throw new Error("No node data");
return {
id: n.id,
workspaces: new Set(data.workspaces.map((w) => w.RepoTags[0]?.split(":")[0])),
};
}),
);
const availableNodes = nodeMetadata.reduce((acc: string[], n) => {
if (n.workspaces.has(w.dockerImage)) acc.push(n.id);
return acc;
}, []);
return {
nodes: availableNodes,
...w,
};
}),
);
const { nodes } = getConfig();
return await Promise.all(
(await db.select().from(workspace)).map(async (w) => {
const nodeMetadata = await Promise.all(
nodes.map(async (n) => {
const { data } = await stardustConnector(n).workspaces.index.get();
if (!data) throw new Error("No node data");
return {
id: n.id,
workspaces: new Set(data.workspaces.map((w) => w.RepoTags[0]?.split(":")[0])),
};
}),
);
const availableNodes = nodeMetadata.reduce((acc: string[], n) => {
if (n.workspaces.has(w.dockerImage)) acc.push(n.id);
return acc;
}, []);
return {
nodes: availableNodes,
...w,
};
}),
);
}
Loading

0 comments on commit fef32c7

Please sign in to comment.