roster-server 1.6.2 → 1.6.4

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 +33 -25
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -24,44 +24,51 @@ class Roster {
24
24
  this.loadSites();
25
25
  }
26
26
 
27
- loadSites() {
27
+ async loadSites() {
28
28
  // Check if wwwPath exists
29
29
  if (!fs.existsSync(this.wwwPath)) {
30
30
  console.warn(`⚠️ WWW path does not exist: ${this.wwwPath}`);
31
31
  return;
32
32
  }
33
33
 
34
- fs.readdirSync(this.wwwPath, { withFileTypes: true })
35
- .filter(dirent => dirent.isDirectory())
36
- .forEach((dirent) => {
37
- const domain = dirent.name;
38
- const domainPath = path.join(this.wwwPath, domain);
34
+ const dirents = fs.readdirSync(this.wwwPath, { withFileTypes: true })
35
+ .filter(dirent => dirent.isDirectory());
39
36
 
40
- const possibleIndexFiles = ['js', 'mjs', 'cjs'].map(ext => `${this.filename}.${ext}`);
41
- let siteApp;
42
- let loadedFile;
37
+ for (const dirent of dirents) {
38
+ const domain = dirent.name;
39
+ const domainPath = path.join(this.wwwPath, domain);
43
40
 
44
- for (const indexFile of possibleIndexFiles) {
45
- const indexPath = path.join(domainPath, indexFile);
46
- if (fs.existsSync(indexPath)) {
47
- siteApp = require(indexPath);
41
+ const possibleIndexFiles = ['js', 'mjs', 'cjs'].map(ext => `${this.filename}.${ext}`);
42
+ let siteApp;
43
+ let loadedFile;
44
+
45
+ for (const indexFile of possibleIndexFiles) {
46
+ const indexPath = path.join(domainPath, indexFile);
47
+ if (fs.existsSync(indexPath)) {
48
+ try {
49
+ siteApp = await import(indexPath);
50
+ // If the module has a default export, use that
51
+ siteApp = siteApp.default || siteApp;
48
52
  loadedFile = indexFile;
49
53
  break;
54
+ } catch (err) {
55
+ console.warn(`⚠️ Error loading ${indexPath}:`, err);
50
56
  }
51
57
  }
58
+ }
52
59
 
53
- if (siteApp) {
54
- const domainEntries = [domain, `www.${domain}`];
55
- this.domains.push(...domainEntries);
56
- domainEntries.forEach(d => {
57
- this.sites[d] = siteApp;
58
- });
60
+ if (siteApp) {
61
+ const domainEntries = [domain, `www.${domain}`];
62
+ this.domains.push(...domainEntries);
63
+ domainEntries.forEach(d => {
64
+ this.sites[d] = siteApp;
65
+ });
59
66
 
60
- console.log(`✅ Loaded site: ${domain} (using ${loadedFile})`);
61
- } else {
62
- console.warn(`⚠️ No index file (js/mjs/cjs) found in ${domainPath}`);
63
- }
64
- });
67
+ console.log(`✅ Loaded site: ${domain} (using ${loadedFile})`);
68
+ } else {
69
+ console.warn(`⚠️ No index file (js/mjs/cjs) found in ${domainPath}`);
70
+ }
71
+ }
65
72
  }
66
73
 
67
74
  generateConfigJson() {
@@ -189,7 +196,8 @@ class Roster {
189
196
  console.log(`✅ Manually registered site: ${domain}`);
190
197
  }
191
198
 
192
- start() {
199
+ async start() {
200
+ await this.loadSites();
193
201
  this.generateConfigJson();
194
202
 
195
203
  const greenlock = Greenlock.init({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roster-server",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "👾 RosterServer - A domain host router to host multiple HTTPS.",
5
5
  "main": "index.js",
6
6
  "scripts": {