Skip to content

Commit

Permalink
refactor: update methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Siumauricio committed Jan 5, 2025
1 parent 9847008 commit cfe36a9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions apps/dokploy/components/dashboard/compose/monitoring/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export const ShowMonitoringCompose = ({
</div>
<ContainerMonitoring
appName={containerAppName || ""}
BASE_URL={url}
TOKEN={token}
baseUrl={url}
token={token}
/>
</CardContent>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const ContainerMonitoring = ({ appName, baseUrl, token }: Props) => {
}, REFRESH_INTERVAL);

return () => clearInterval(interval);
}, [dataPoints, appName]);
}, [dataPoints, appName, token]);

if (isLoading) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const Service = (
);

const { data: auth } = api.auth.get.useQuery();
const { data: token } = api.admin.getMetricsToken.useQuery();
const { data: user } = api.user.byAuthId.useQuery(
{
authId: auth?.id || "",
Expand Down Expand Up @@ -242,16 +243,15 @@ const Service = (
<ShowEnvironment applicationId={applicationId} />
</div>
</TabsContent>
{!data?.serverId && (
<TabsContent value="monitoring">
<div className="flex flex-col gap-4 pt-2.5">
<ContainerMonitoring
appName={data?.appName || ""}
BASE_URL={"http://localhost:3001"}
/>
</div>
</TabsContent>
)}
<TabsContent value="monitoring">
<div className="flex flex-col gap-4 pt-2.5">
<ContainerMonitoring
appName={data?.appName || ""}
baseUrl={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:4500"}`}
token={data?.server?.metricsToken || token || ""}
/>
</div>
</TabsContent>

<TabsContent value="logs">
<div className="flex flex-col gap-4 pt-2.5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const Service = (
);

const { data: auth } = api.auth.get.useQuery();
const { data: token } = api.admin.getMetricsToken.useQuery();
const { data: user } = api.user.byAuthId.useQuery(
{
authId: auth?.id || "",
Expand Down Expand Up @@ -243,9 +244,9 @@ const Service = (
<div className="flex flex-col gap-4 pt-2.5">
<ShowMonitoringCompose
serverId={data?.serverId || ""}
url={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:3001"}`}
url={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:4500"}`}
appName={data?.appName || ""}
token={data?.server?.metricsToken || ""}
token={data?.server?.metricsToken || token || ""}
appType={data?.composeType || "docker-compose"}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const Mariadb = (
const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.mariadb.one.useQuery({ mariadbId });
const { data: auth } = api.auth.get.useQuery();
const { data: token } = api.admin.getMetricsToken.useQuery();
const { data: user } = api.user.byAuthId.useQuery(
{
authId: auth?.id || "",
Expand Down Expand Up @@ -216,7 +217,8 @@ const Mariadb = (
<div className="flex flex-col gap-4 pt-2.5">
<ContainerMonitoring
appName={data?.appName || ""}
BASE_URL={"http://localhost:3001"}
baseUrl={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:4500"}`}
token={data?.server?.metricsToken || token || ""}
/>
</div>
</TabsContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Mongo = (
const { data } = api.mongo.one.useQuery({ mongoId });

const { data: auth } = api.auth.get.useQuery();
const { data: token } = api.admin.getMetricsToken.useQuery();
const { data: user } = api.user.byAuthId.useQuery(
{
authId: auth?.id || "",
Expand Down Expand Up @@ -218,7 +219,8 @@ const Mongo = (
<div className="flex flex-col gap-4 pt-2.5">
<ContainerMonitoring
appName={data?.appName || ""}
BASE_URL={"http://localhost:3001"}
baseUrl={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:4500"}`}
token={data?.server?.metricsToken || token || ""}
/>
{/* <DockerMonitoring appName={data?.appName || ""} /> */}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const MySql = (
const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.mysql.one.useQuery({ mysqlId });
const { data: auth } = api.auth.get.useQuery();
const { data: token } = api.admin.getMetricsToken.useQuery();
const { data: user } = api.user.byAuthId.useQuery(
{
authId: auth?.id || "",
Expand Down Expand Up @@ -217,7 +218,8 @@ const MySql = (
<div className="flex flex-col gap-4 pt-2.5">
<ContainerMonitoring
appName={data?.appName || ""}
BASE_URL={"http://localhost:3001"}
baseUrl={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:4500"}`}
token={data?.server?.metricsToken || token || ""}
/>
{/* <DockerMonitoring appName={data?.appName || ""} /> */}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const Postgresql = (
const [tab, setSab] = useState<TabState>(activeTab);
const { data } = api.postgres.one.useQuery({ postgresId });
const { data: auth } = api.auth.get.useQuery();
const { data: token } = api.admin.getMetricsToken.useQuery();
const { data: user } = api.user.byAuthId.useQuery(
{
authId: auth?.id || "",
Expand Down Expand Up @@ -218,7 +219,8 @@ const Postgresql = (
<div className="flex flex-col gap-4 pt-2.5">
<ContainerMonitoring
appName={data?.appName || ""}
BASE_URL={"http://localhost:3001"}
baseUrl={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:4500"}`}
token={data?.server?.metricsToken || token || ""}
/>
</div>
</TabsContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const Redis = (
const { data } = api.redis.one.useQuery({ redisId });

const { data: auth } = api.auth.get.useQuery();
const { data: token } = api.admin.getMetricsToken.useQuery();
const { data: user } = api.user.byAuthId.useQuery(
{
authId: auth?.id || "",
Expand Down Expand Up @@ -216,7 +217,8 @@ const Redis = (
<div className="flex flex-col gap-4 pt-2.5">
<ContainerMonitoring
appName={data?.appName || ""}
BASE_URL={"http://localhost:3001"}
baseUrl={`${data?.serverId ? `http://${data?.server?.ipAddress}:${data?.server?.defaultPortMetrics}` : "http://localhost:4500"}`}
token={data?.server?.metricsToken || token || ""}
/>
{/* <DockerMonitoring appName={data?.appName || ""} /> */}
</div>
Expand Down
11 changes: 10 additions & 1 deletion apps/dokploy/server/api/routers/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import {
} from "@dokploy/server";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
import { adminProcedure, createTRPCRouter, publicProcedure } from "../trpc";
import {
adminProcedure,
createTRPCRouter,
protectedProcedure,
publicProcedure,
} from "../trpc";

export const adminRouter = createTRPCRouter({
one: adminProcedure.query(async ({ ctx }) => {
Expand Down Expand Up @@ -146,4 +151,8 @@ export const adminRouter = createTRPCRouter({
throw error;
}
}),
getMetricsToken: protectedProcedure.query(async ({ ctx }) => {
const admin = await findAdminById(ctx.user.adminId);
return admin.metricsToken;
}),
});

0 comments on commit cfe36a9

Please sign in to comment.