mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: add option to activate the request distribution
This commit is contained in:
@@ -24,6 +24,11 @@ export const ShowRequests = () => {
|
|||||||
const { mutateAsync: deactivateLogRotate } =
|
const { mutateAsync: deactivateLogRotate } =
|
||||||
api.settings.deactivateLogRotate.useMutation();
|
api.settings.deactivateLogRotate.useMutation();
|
||||||
|
|
||||||
|
const { data: isActive, refetch } =
|
||||||
|
api.settings.haveActivateRequests.useQuery();
|
||||||
|
const { mutateAsync: toggleRequests } =
|
||||||
|
api.settings.toggleRequests.useMutation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card className="bg-transparent mt-10">
|
<Card className="bg-transparent mt-10">
|
||||||
@@ -33,39 +38,62 @@ export const ShowRequests = () => {
|
|||||||
<CardDescription>
|
<CardDescription>
|
||||||
<span>Showing web and API requests over time</span>
|
<span>Showing web and API requests over time</span>
|
||||||
</CardDescription>
|
</CardDescription>
|
||||||
{!isLogRotateActive && (
|
<div className="flex w-fit gap-4">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
mutateAsync()
|
mutateAsync()
|
||||||
.then(() => {
|
.then(async () => {
|
||||||
toast.success("Log rotate activated");
|
await toggleRequests({ enable: !isActive })
|
||||||
refetchLogRotate();
|
.then(() => {
|
||||||
|
refetch();
|
||||||
|
toast.success("Access Log Added to Traefik");
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.error(err.message);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
toast.error(err.message);
|
toast.error(err.message);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Activate Log Rotate
|
{isActive ? "Deactivate" : "Activate"}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
{!isLogRotateActive && (
|
||||||
|
<Button
|
||||||
{isLogRotateActive && (
|
variant="secondary"
|
||||||
<Button
|
onClick={() => {
|
||||||
onClick={() => {
|
mutateAsync()
|
||||||
deactivateLogRotate()
|
.then(() => {
|
||||||
.then(() => {
|
toast.success("Log rotate activated");
|
||||||
toast.success("Log rotate deactivated");
|
refetchLogRotate();
|
||||||
refetchLogRotate();
|
})
|
||||||
})
|
.catch((err) => {
|
||||||
.catch((err) => {
|
toast.error(err.message);
|
||||||
toast.error(err.message);
|
});
|
||||||
});
|
}}
|
||||||
}}
|
>
|
||||||
>
|
Activate Log Rotate
|
||||||
Deactivate Log Rotate
|
</Button>
|
||||||
</Button>
|
)}
|
||||||
)}
|
{isLogRotateActive && (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() => {
|
||||||
|
deactivateLogRotate()
|
||||||
|
.then(() => {
|
||||||
|
toast.success("Log rotate deactivated");
|
||||||
|
refetchLogRotate();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.error(err.message);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Deactivate Log Rotate
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import {
|
|||||||
} from "../services/settings";
|
} from "../services/settings";
|
||||||
import { canAccessToTraefikFiles } from "../services/user";
|
import { canAccessToTraefikFiles } from "../services/user";
|
||||||
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
|
import { dump, load } from "js-yaml";
|
||||||
|
|
||||||
export const settingsRouter = createTRPCRouter({
|
export const settingsRouter = createTRPCRouter({
|
||||||
reloadServer: adminProcedure.mutation(async () => {
|
reloadServer: adminProcedure.mutation(async () => {
|
||||||
@@ -382,4 +383,64 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
getLogRotateStatus: adminProcedure.query(async () => {
|
getLogRotateStatus: adminProcedure.query(async () => {
|
||||||
return await logRotationManager.getStatus();
|
return await logRotationManager.getStatus();
|
||||||
}),
|
}),
|
||||||
|
haveActivateRequests: adminProcedure.query(async () => {
|
||||||
|
const config = readMainConfig();
|
||||||
|
|
||||||
|
if (!config) return false;
|
||||||
|
const parsedConfig = load(config) as {
|
||||||
|
accessLog?: {
|
||||||
|
filePath: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return !!parsedConfig?.accessLog?.filePath;
|
||||||
|
}),
|
||||||
|
toggleRequests: adminProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
enable: z.boolean(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.mutation(async ({ input }) => {
|
||||||
|
const config = readMainConfig();
|
||||||
|
if (!config) return false;
|
||||||
|
|
||||||
|
if (input.enable) {
|
||||||
|
const parsedConfig = load(config) as {
|
||||||
|
accessLog?: {
|
||||||
|
filePath: string;
|
||||||
|
format: string;
|
||||||
|
bufferingSize: number;
|
||||||
|
filters?: {
|
||||||
|
retryAttempts?: boolean;
|
||||||
|
minDuration?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const config2 = {
|
||||||
|
accessLog: {
|
||||||
|
filePath: "/etc/dokploy/traefik/dynamic/access.log",
|
||||||
|
format: "json",
|
||||||
|
bufferingSize: 100,
|
||||||
|
filters: {
|
||||||
|
retryAttempts: true,
|
||||||
|
minDuration: "10ms",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
parsedConfig.accessLog = config2.accessLog;
|
||||||
|
writeMainConfig(dump(parsedConfig));
|
||||||
|
} else {
|
||||||
|
const parsedConfig = load(config) as {
|
||||||
|
accessLog?: {
|
||||||
|
filePath: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
delete parsedConfig.accessLog;
|
||||||
|
writeMainConfig(dump(parsedConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,12 +59,6 @@ export const createApplication = async (
|
|||||||
|
|
||||||
if (process.env.NODE_ENV === "development") {
|
if (process.env.NODE_ENV === "development") {
|
||||||
createTraefikConfig(newApplication.appName);
|
createTraefikConfig(newApplication.appName);
|
||||||
await tx.insert(domains).values({
|
|
||||||
applicationId: newApplication.applicationId,
|
|
||||||
host: `${newApplication.appName}.docker.localhost`,
|
|
||||||
port: process.env.NODE_ENV === "development" ? 3000 : 80,
|
|
||||||
certificateType: "none",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newApplication;
|
return newApplication;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fs, { writeFileSync } from "node:fs";
|
import fs, { writeFileSync } from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { Domain } from "@/server/api/services/domain";
|
import type { Domain } from "@/server/api/services/domain";
|
||||||
import { DYNAMIC_TRAEFIK_PATH } from "@/server/constants";
|
import { DYNAMIC_TRAEFIK_PATH, MAIN_TRAEFIK_PATH } from "@/server/constants";
|
||||||
import { dump, load } from "js-yaml";
|
import { dump, load } from "js-yaml";
|
||||||
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
|
import type { FileConfig, HttpLoadBalancerService } from "./file-types";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user