roster-server 1.7.2 → 1.7.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 +42 -37
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -20,54 +20,57 @@ 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
|
-
loadSites() {
|
|
25
|
+
async loadSites() {
|
|
28
26
|
// Check if wwwPath exists
|
|
29
27
|
if (!fs.existsSync(this.wwwPath)) {
|
|
30
28
|
console.warn(`⚠️ WWW path does not exist: ${this.wwwPath}`);
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
fs.readdirSync(this.wwwPath, { withFileTypes: true })
|
|
35
|
-
.filter(dirent => dirent.isDirectory())
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
const sites = fs.readdirSync(this.wwwPath, { withFileTypes: true })
|
|
33
|
+
.filter(dirent => dirent.isDirectory());
|
|
34
|
+
|
|
35
|
+
for (const dirent of sites) {
|
|
36
|
+
const domain = dirent.name;
|
|
37
|
+
const domainPath = path.join(this.wwwPath, domain);
|
|
38
|
+
|
|
39
|
+
const possibleIndexFiles = ['js', 'mjs', 'cjs'].map(ext => `${this.filename}.${ext}`);
|
|
40
|
+
let siteApp;
|
|
41
|
+
let loadedFile;
|
|
42
|
+
|
|
43
|
+
for (const indexFile of possibleIndexFiles) {
|
|
44
|
+
const indexPath = path.join(domainPath, indexFile);
|
|
45
|
+
if (fs.existsSync(indexPath)) {
|
|
46
|
+
try {
|
|
47
|
+
// Try dynamic import first
|
|
48
|
+
siteApp = await import(indexPath).catch(() => {
|
|
49
|
+
// Fallback to require for CommonJS modules
|
|
50
|
+
return require(indexPath);
|
|
51
|
+
});
|
|
52
|
+
// Handle default exports
|
|
53
|
+
siteApp = siteApp.default || siteApp;
|
|
54
|
+
loadedFile = indexFile;
|
|
55
|
+
break;
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.warn(`⚠️ Error loading ${indexPath}:`, err);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
60
|
+
}
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
if (siteApp) {
|
|
63
|
+
const domainEntries = [domain, `www.${domain}`];
|
|
64
|
+
this.domains.push(...domainEntries);
|
|
65
|
+
domainEntries.forEach(d => {
|
|
66
|
+
this.sites[d] = siteApp;
|
|
67
|
+
});
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
console.log(`✅ Loaded site: ${domain} (using ${loadedFile})`);
|
|
70
|
+
} else {
|
|
71
|
+
console.warn(`⚠️ No index file (js/mjs/cjs) found in ${domainPath}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
generateConfigJson() {
|
|
@@ -193,9 +196,11 @@ class Roster {
|
|
|
193
196
|
});
|
|
194
197
|
|
|
195
198
|
console.log(`✅ Manually registered site: ${domain}`);
|
|
199
|
+
return this;
|
|
196
200
|
}
|
|
197
201
|
|
|
198
|
-
start() {
|
|
202
|
+
async start() {
|
|
203
|
+
await this.loadSites();
|
|
199
204
|
this.generateConfigJson();
|
|
200
205
|
|
|
201
206
|
const greenlock = Greenlock.init({
|