Skip to content

Commit 25bf15d

Browse files
committed
enhance maintenance handling and improve subdomain matching logic
1 parent 8b015f1 commit 25bf15d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

html/maintenance.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export default function maintenanceHtml(globalMaintenance, subdomainsMaintenance
1414
bannerMessageLabel: 'Message du bandeau :',
1515
update: 'Mettre à jour',
1616
addBannerSubdomainLabel: 'Ajouter un sous-domaine pour le bandeau :',
17-
bannerSubdomainPlaceholder: 'ex: admin.monsite.com',
18-
bannerInfo: 'Le bandeau s\'affiche sur les sous-domaines listés ci-dessus'
17+
bannerSubdomainPlaceholder: 'ex: admin.monsite.com ou *.monsite.com',
18+
bannerInfo: 'Le bandeau s\'affiche sur les sous-domaines listés ci-dessus. Utilisez *.domaine.fr pour cibler tous les sous-domaines.'
1919
},
2020
EN: {
2121
title: 'Maintenance Control',
@@ -31,8 +31,8 @@ export default function maintenanceHtml(globalMaintenance, subdomainsMaintenance
3131
bannerMessageLabel: 'Banner message:',
3232
update: 'Update',
3333
addBannerSubdomainLabel: 'Add a subdomain for the banner:',
34-
bannerSubdomainPlaceholder: 'ex: admin.mysite.com',
35-
bannerInfo: 'The banner is displayed on the subdomains listed above'
34+
bannerSubdomainPlaceholder: 'ex: admin.mysite.com or *.mysite.com',
35+
bannerInfo: 'The banner is displayed on the subdomains listed above. Use *.domain.com to target all subdomains.'
3636
}
3737
};
3838

worker.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import { c_redirect } from './custom-redirect.js'
22
import maintenanceHtml from './html/maintenance.js'
33
import { handleApi } from './handle-api.js'
44

5+
// Check if a host matches any pattern in a list (supports *.domain.fr wildcards)
6+
function hostMatchesAny(host, patterns) {
7+
if (!host || !Array.isArray(patterns)) return false;
8+
return patterns.some(pattern => {
9+
if (pattern.startsWith('*.')) {
10+
const suffix = pattern.slice(1); // ".domain.fr"
11+
return host.endsWith(suffix) && host !== pattern.slice(2);
12+
}
13+
return host === pattern;
14+
});
15+
}
16+
517
// Helper to safely parse JSON
618
function safeJsonParse(str, fallback) {
719
try { return JSON.parse(str || ''); } catch { return fallback; }
@@ -190,7 +202,7 @@ export default {
190202
if (env.ENABLE_4G_BANNER && state.is4gMode) {
191203
showBanner = true;
192204
bannerMessage = env.TEXT_4G_BANNER_MESSAGE;
193-
} else if (state.bannerMessage && state.bannerSubdomains.includes(host)) {
205+
} else if (state.bannerMessage && hostMatchesAny(host, state.bannerSubdomains)) {
194206
showBanner = true;
195207
bannerMessage = state.bannerMessage;
196208
}

0 commit comments

Comments
 (0)