41c37156af
added formatter type to associate a service with their templates and filepaths
27 lines
663 B
TypeScript
27 lines
663 B
TypeScript
import type { Service } from "./types";
|
|
|
|
/**
|
|
should validate config, for now just checks for port collisions
|
|
**/
|
|
export class ConfigValidator {
|
|
static validatecaddyfile(services: Service[]){
|
|
const hostports = new Map<string, Set<number>>();
|
|
|
|
for (const service of services) {
|
|
const hostip = service.host.ip;
|
|
|
|
if (!hostports.has(hostip)) {
|
|
hostports.set(hostip, new Set());
|
|
}
|
|
|
|
const ports = hostports.get(hostip)!;
|
|
if (ports.has(service.port)) {
|
|
throw new Error(`port collision: host ${hostip} already has a service on ${service.port}(${service.name})`)
|
|
}
|
|
ports.add(service.port);
|
|
}
|
|
|
|
console.log("validated collision");
|
|
}
|
|
}
|