roster-server 1.6.4 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +25 -33
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -31,44 +31,37 @@ class Roster {
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
.filter(dirent => dirent.isDirectory())
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (fs.existsSync(indexPath)) {
|
|
48
|
-
try {
|
|
34
|
+
fs.readdirSync(this.wwwPath, { withFileTypes: true })
|
|
35
|
+
.filter(dirent => dirent.isDirectory())
|
|
36
|
+
.forEach(async (dirent) => {
|
|
37
|
+
const domain = dirent.name;
|
|
38
|
+
const domainPath = path.join(this.wwwPath, domain);
|
|
39
|
+
|
|
40
|
+
const possibleIndexFiles = ['js', 'mjs', 'cjs'].map(ext => `${this.filename}.${ext}`);
|
|
41
|
+
let siteApp;
|
|
42
|
+
let loadedFile;
|
|
43
|
+
|
|
44
|
+
for (const indexFile of possibleIndexFiles) {
|
|
45
|
+
const indexPath = path.join(domainPath, indexFile);
|
|
46
|
+
if (fs.existsSync(indexPath)) {
|
|
49
47
|
siteApp = await import(indexPath);
|
|
50
|
-
// If the module has a default export, use that
|
|
51
|
-
siteApp = siteApp.default || siteApp;
|
|
52
48
|
loadedFile = indexFile;
|
|
53
49
|
break;
|
|
54
|
-
} catch (err) {
|
|
55
|
-
console.warn(`⚠️ Error loading ${indexPath}:`, err);
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
|
-
}
|
|
59
52
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
if (siteApp) {
|
|
54
|
+
const domainEntries = [domain, `www.${domain}`];
|
|
55
|
+
this.domains.push(...domainEntries);
|
|
56
|
+
domainEntries.forEach(d => {
|
|
57
|
+
this.sites[d] = siteApp;
|
|
58
|
+
});
|
|
66
59
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
console.log(`✅ Loaded site: ${domain} (using ${loadedFile})`);
|
|
61
|
+
} else {
|
|
62
|
+
console.warn(`⚠️ No index file (js/mjs/cjs) found in ${domainPath}`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
72
65
|
}
|
|
73
66
|
|
|
74
67
|
generateConfigJson() {
|
|
@@ -196,8 +189,7 @@ class Roster {
|
|
|
196
189
|
console.log(`✅ Manually registered site: ${domain}`);
|
|
197
190
|
}
|
|
198
191
|
|
|
199
|
-
|
|
200
|
-
await this.loadSites();
|
|
192
|
+
start() {
|
|
201
193
|
this.generateConfigJson();
|
|
202
194
|
|
|
203
195
|
const greenlock = Greenlock.init({
|