[Docker Monitor] Change tcp:// to http://

This commit is contained in:
Louis Lam 2022-10-04 16:19:56 +08:00
parent 1c4e97439c
commit 0686757160
4 changed files with 18 additions and 4 deletions

View file

@ -75,7 +75,7 @@ class DockerHost {
if (dockerHost.dockerType === "socket") {
options.socketPath = dockerHost.dockerDaemon;
} else if (dockerHost.dockerType === "tcp") {
options.baseURL = dockerHost.dockerDaemon;
options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon);
}
let res = await axios.request(options);
@ -99,6 +99,18 @@ class DockerHost {
}
}
/**
* Since axios 0.27.X, it does not accept `tcp://` protocol.
* Change it to `http://` on the fly in order to fix it. (https://github.com/louislam/uptime-kuma/issues/2165)
*/
static patchDockerURL(url) {
if (typeof url === "string") {
// Replace the first occurrence only with g
return url.replace(/tcp:\/\//g, "http://");
}
return url;
}
}
module.exports = {