mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-20 12:04:29 +00:00
Fixes #4365 — traefik.me had availability issues. sslip.io uses the same IP-in-subdomain format, supports both IPv4 and IPv6, and is more reliable.
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { randomBytes } from "node:crypto";
|
|
import type { Domain } from "@dokploy/server";
|
|
|
|
export interface Schema {
|
|
serverIp: string;
|
|
projectName: string;
|
|
}
|
|
|
|
export type DomainSchema = Pick<Domain, "host" | "port" | "serviceName"> & {
|
|
path?: string;
|
|
};
|
|
|
|
export interface Template {
|
|
envs?: string[];
|
|
mounts?: {
|
|
filePath: string;
|
|
content?: string;
|
|
}[];
|
|
domains?: DomainSchema[];
|
|
}
|
|
|
|
export const generateRandomDomain = ({
|
|
serverIp,
|
|
projectName,
|
|
}: {
|
|
serverIp: string;
|
|
projectName: string;
|
|
}): string => {
|
|
const hash = randomBytes(3).toString("hex");
|
|
const slugIp = serverIp.replaceAll(".", "-");
|
|
|
|
return `${projectName}-${hash}${slugIp === "" ? "" : `-${slugIp}`}.sslip.io`;
|
|
};
|
|
|
|
export const generateHash = (projectName: string, quantity = 3): string => {
|
|
const hash = randomBytes(quantity).toString("hex");
|
|
return `${projectName}-${hash}`;
|
|
};
|
|
|
|
export const generatePassword = (quantity = 16): string => {
|
|
const characters =
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
let password = "";
|
|
for (let i = 0; i < quantity; i++) {
|
|
password += characters.charAt(
|
|
Math.floor(Math.random() * characters.length),
|
|
);
|
|
}
|
|
return password.toLowerCase();
|
|
};
|
|
|
|
export const generateBase64 = (bytes = 32): string => {
|
|
return randomBytes(bytes).toString("base64");
|
|
};
|