Skip to content

Commit 337ce4d

Browse files
authored
Merge pull request #1 from kalayciburak/feature/service-url-extraction
feat: enhance service URL extraction for MinIO and other services
2 parents 79f6aa9 + e4e1034 commit 337ce4d

1 file changed

Lines changed: 45 additions & 7 deletions

File tree

client/src/services/resourceMapper.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,69 @@
11
import { extractFqdns } from "../utils/urlUtils";
22
import { RESOURCE_TYPES } from "../constants/resourceTypes";
33

4+
const extractFromCompose = (compose, key) => {
5+
if (!compose || !key) return [];
6+
const re = new RegExp(`${key}\\s*:\\s*'?([^'\\n]+)'?`, "i");
7+
const m = compose.match(re);
8+
if (!m?.[1]) return [];
9+
return m[1]
10+
.split(/[,\s]+/)
11+
.map((s) => s.trim())
12+
.filter(Boolean);
13+
};
14+
15+
const pickMinioPreferred = (urls) => {
16+
if (!urls?.length) return urls;
17+
const consoleUrls = urls.filter((u) => /console[-.]/i.test(u));
18+
if (consoleUrls.length) {
19+
const rest = urls.filter((u) => !/console[-.]/i.test(u));
20+
return [...consoleUrls, ...rest];
21+
}
22+
return urls;
23+
};
24+
425
export const mapApplication = (app) => ({
526
...app,
627
type: RESOURCE_TYPES.APPLICATION,
728
fqdns: extractFqdns(app.fqdn),
829
});
930

1031
export const mapService = (service) => {
11-
const serviceFqdns = [];
32+
let fqdns = [];
1233

13-
if (service.applications && service.applications.length > 0) {
14-
service.applications.forEach((app) => {
34+
if (service.applications?.length) {
35+
for (const app of service.applications) {
1536
if (app.fqdn) {
16-
serviceFqdns.push(...extractFqdns(app.fqdn));
37+
fqdns.push(...extractFqdns(app.fqdn));
1738
}
18-
});
39+
}
1940
}
2041

2142
if (service.fqdn) {
22-
serviceFqdns.push(...extractFqdns(service.fqdn));
43+
fqdns.push(...extractFqdns(service.fqdn));
44+
}
45+
46+
const envUrls =
47+
service.environment?.COOLIFY_URL ||
48+
service.environment?.COOLIFY_FQDN ||
49+
null;
50+
if (envUrls) {
51+
fqdns.push(...extractFqdns(envUrls));
52+
} else if (service.docker_compose) {
53+
fqdns.push(...extractFromCompose(service.docker_compose, "COOLIFY_URL"));
54+
if (!fqdns.length) {
55+
fqdns.push(...extractFromCompose(service.docker_compose, "COOLIFY_FQDN"));
56+
}
2357
}
2458

59+
const uniq = [...new Set(fqdns)];
60+
const serviceType = (service.service_type || service.type || "").toString().toLowerCase();
61+
const ordered = serviceType === "minio" ? pickMinioPreferred(uniq) : uniq;
62+
2563
return {
2664
...service,
2765
type: RESOURCE_TYPES.SERVICE,
28-
fqdns: [...new Set(serviceFqdns)],
66+
fqdns: ordered,
2967
status: service.status || service.applications?.[0]?.status,
3068
};
3169
};

0 commit comments

Comments
 (0)