roster-server 1.6.0 → 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 (3) hide show
  1. package/README.md +10 -0
  2. package/index.js +34 -26
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -111,6 +111,16 @@ module.exports = (httpsServer) => {
111
111
  };
112
112
  ```
113
113
 
114
+ 4. **Manual**:
115
+ ```javascript:demo/www/manual.js
116
+ roster.register('example.com', (httpsServer) => {
117
+ return (req, res) => {
118
+ res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
119
+ res.end('"Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
120
+ };
121
+ });
122
+ ```
123
+
114
124
  ### Running the Server
115
125
 
116
126
  ```bash
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({
@@ -204,7 +212,7 @@ class Roster {
204
212
  this.handleRequest(req, res);
205
213
  };
206
214
 
207
- greenlock.ready(glx => {
215
+ return greenlock.ready(glx => {
208
216
  // Obtener los servidores sin iniciarlos
209
217
  const httpsServer = glx.httpsServer(null, app);
210
218
  const httpServer = glx.httpServer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roster-server",
3
- "version": "1.6.0",
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": {