refactor: add is cloud to fn

This commit is contained in:
Mauricio Siu
2024-12-21 13:19:30 -06:00
parent e42e9bec17
commit 59c0636fb0
2 changed files with 14 additions and 5 deletions

View File

@@ -721,6 +721,12 @@ export const settingsRouter = createTRPCRouter({
) )
.mutation(async ({ input }) => { .mutation(async ({ input }) => {
try { try {
if (IS_CLOUD && !input.serverId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "Please set a serverId to update Traefik ports",
});
}
await initializeTraefik({ await initializeTraefik({
serverId: input.serverId, serverId: input.serverId,
additionalPorts: input.additionalPorts, additionalPorts: input.additionalPorts,
@@ -729,7 +735,10 @@ export const settingsRouter = createTRPCRouter({
} catch (error) { } catch (error) {
throw new TRPCError({ throw new TRPCError({
code: "BAD_REQUEST", code: "BAD_REQUEST",
message: "Failed to update Traefik ports", message:
error instanceof Error
? error.message
: "Error to update Traefik ports",
cause: error, cause: error,
}); });
} }
@@ -749,12 +758,12 @@ export const settingsRouter = createTRPCRouter({
stdout = result.stdout; stdout = result.stdout;
} }
const ports: Array<{ const ports: {
Protocol: string; Protocol: string;
TargetPort: number; TargetPort: number;
PublishedPort: number; PublishedPort: number;
PublishMode: string; PublishMode: string;
}> = JSON.parse(stdout.trim()); }[] = JSON.parse(stdout.trim());
// Filter out the default ports (80, 443, and optionally 8080) // Filter out the default ports (80, 443, and optionally 8080)
const additionalPorts = ports const additionalPorts = ports

View File

@@ -16,11 +16,11 @@ interface TraefikOptions {
enableDashboard?: boolean; enableDashboard?: boolean;
env?: string[]; env?: string[];
serverId?: string; serverId?: string;
additionalPorts?: Array<{ additionalPorts?: {
targetPort: number; targetPort: number;
publishedPort: number; publishedPort: number;
publishMode?: "ingress" | "host"; publishMode?: "ingress" | "host";
}>; }[];
} }
export const initializeTraefik = async ({ export const initializeTraefik = async ({