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.
Files changed (2) hide show
  1. package/index.js +42 -37
  2. 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
- .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)) {
47
- try {
48
- siteApp = await import(indexPath);
49
- siteApp = siteApp.default || siteApp;
50
- loadedFile = indexFile;
51
- break;
52
- } catch (err) {
53
- console.warn(`⚠️ Error loading ${indexPath}:`, err.message);
54
- continue;
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
- if (siteApp) {
60
- const domainEntries = [domain, `www.${domain}`];
61
- this.domains.push(...domainEntries);
62
- domainEntries.forEach(d => {
63
- this.sites[d] = siteApp;
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
- console.log(`✅ Loaded site: ${domain} (using ${loadedFile})`);
67
- } else {
68
- console.warn(`⚠️ No index file (js/mjs/cjs) found in ${domainPath}`);
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({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roster-server",
3
- "version": "1.7.2",
3
+ "version": "1.7.6",
4
4
  "description": "👾 RosterServer - A domain host router to host multiple HTTPS.",
5
5
  "main": "index.js",
6
6
  "scripts": {