IC, Caddyfile
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import type { Service } from "./types";
|
||||
|
||||
/**
|
||||
should validate config, for now just checks for port collisions
|
||||
**/
|
||||
export class ConfigValidator {
|
||||
static validate(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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user