diff --git a/src/command/impl/addSubPathCommand.py b/src/command/impl/addSubPathCommand.py index 2f49bee..3fd8ac3 100644 --- a/src/command/impl/addSubPathCommand.py +++ b/src/command/impl/addSubPathCommand.py @@ -33,7 +33,7 @@ class AddSubPathCommand(Command): print(f"Service host \"{serviceHost}\" is not a valid URL") return - print(f"Adding \"{domain}\" -> \"{serviceHost}\"") + print(f"Adding \"{domain}{path}\" -> \"{serviceHost}\"") traefikConfig.addSubPathRouter(subPathName, domain, path, serviceHost) traefikConfig.save() diff --git a/src/traefik/traefikConfig.py b/src/traefik/traefikConfig.py index 04aa230..24b34e1 100644 --- a/src/traefik/traefikConfig.py +++ b/src/traefik/traefikConfig.py @@ -39,7 +39,18 @@ class TraefikConfig: } def addSubPathRouter(self, name, domain, path, serviceHost): - self.addPathRewrite(name, path) + # Add trailing slashs + if not path.endswith("/"): + path += "/" + if not serviceHost.endswith("/"): + serviceHost += "/" + + # Add path stripper middleware + self.configYml["http"]["middlewares"][name] = { + "stripPrefix": { + "prefixes": [path] + } + } # Add router self.configYml["http"]["routers"][name] = { @@ -50,10 +61,6 @@ class TraefikConfig: "service": name } - # Add trailing slash - if not serviceHost.endswith("/"): - serviceHost += "/" - # Add service self.configYml["http"]["services"][name] = { "loadBalancer": { @@ -77,16 +84,6 @@ class TraefikConfig: def hasPathRewrite(self, name): return name in self.configYml["http"]["middlewares"] - - def addPathRewrite(self, name, path): - if not path.endswith("/"): # Add trailing slash - path += "/" - - self.configYml["http"]["middlewares"][name] = { - "stripPrefix": { - "prefixes": [path] - } - } def hasService(self, name): return name in self.configYml["http"]["services"]