roster-server 1.6.4 → 1.6.8
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 +22 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -20,8 +20,6 @@ class Roster {
|
|
|
20
20
|
throw new Error('⚠️ Port 80 is reserved for ACME challenge. Please use a different port.');
|
|
21
21
|
}
|
|
22
22
|
this.port = port;
|
|
23
|
-
|
|
24
|
-
this.loadSites();
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
async loadSites() {
|
|
@@ -31,44 +29,37 @@ class Roster {
|
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
.filter(dirent => dirent.isDirectory())
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const domainPath = path.join(this.wwwPath, domain);
|
|
32
|
+
fs.readdirSync(this.wwwPath, { withFileTypes: true })
|
|
33
|
+
.filter(dirent => dirent.isDirectory())
|
|
34
|
+
.forEach(async (dirent) => {
|
|
35
|
+
const domain = dirent.name;
|
|
36
|
+
const domainPath = path.join(this.wwwPath, domain);
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
const possibleIndexFiles = ['js', 'mjs', 'cjs'].map(ext => `${this.filename}.${ext}`);
|
|
39
|
+
let siteApp;
|
|
40
|
+
let loadedFile;
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
try {
|
|
42
|
+
for (const indexFile of possibleIndexFiles) {
|
|
43
|
+
const indexPath = path.join(domainPath, indexFile);
|
|
44
|
+
if (fs.existsSync(indexPath)) {
|
|
49
45
|
siteApp = await import(indexPath);
|
|
50
|
-
// If the module has a default export, use that
|
|
51
|
-
siteApp = siteApp.default || siteApp;
|
|
52
46
|
loadedFile = indexFile;
|
|
53
47
|
break;
|
|
54
|
-
} catch (err) {
|
|
55
|
-
console.warn(`⚠️ Error loading ${indexPath}:`, err);
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
|
-
}
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
if (siteApp) {
|
|
52
|
+
const domainEntries = [domain, `www.${domain}`];
|
|
53
|
+
this.domains.push(...domainEntries);
|
|
54
|
+
domainEntries.forEach(d => {
|
|
55
|
+
this.sites[d] = siteApp;
|
|
56
|
+
});
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
console.log(`✅ Loaded site: ${domain} (using ${loadedFile})`);
|
|
59
|
+
} else {
|
|
60
|
+
console.warn(`⚠️ No index file (js/mjs/cjs) found in ${domainPath}`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
72
63
|
}
|
|
73
64
|
|
|
74
65
|
generateConfigJson() {
|