roster-server 1.5.0 → 1.5.2

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 +27 -43
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -12,6 +12,8 @@ class Roster {
12
12
  this.cluster = options.cluster || false;
13
13
  this.domains = [];
14
14
  this.sites = {};
15
+ this.hostname = options.hostname || '0.0.0.0';
16
+ this.filename = options.filename || 'index';
15
17
 
16
18
  const port = options.port || 443;
17
19
  if (port === 80) {
@@ -27,7 +29,7 @@ class Roster {
27
29
  const domain = dirent.name;
28
30
  const domainPath = path.join(this.wwwPath, domain);
29
31
 
30
- const possibleIndexFiles = ['index.js', 'index.mjs', 'index.cjs'];
32
+ const possibleIndexFiles = ['js', 'mjs', 'cjs'].map(ext => `${this.filename}.${ext}`);
31
33
  let siteApp;
32
34
  let loadedFile;
33
35
 
@@ -158,29 +160,6 @@ class Roster {
158
160
  }
159
161
  }
160
162
 
161
- initServers(glx) {
162
- const app = (req, res) => {
163
- this.handleRequest(req, res);
164
- };
165
-
166
- // Obtener los servidores sin iniciarlos
167
- const httpsServer = glx.httpsServer(null, app);
168
- const httpServer = glx.httpServer();
169
-
170
- // Inicializar las aplicaciones Socket.IO con el servidor HTTPS
171
- for (const [host, siteApp] of Object.entries(this.sites)) {
172
- if (!host.startsWith('www.')) {
173
- const appInstance = siteApp(httpsServer);
174
- this.sites[host] = appInstance;
175
- this.sites[`www.${host}`] = appInstance;
176
- console.log(`🔧 Initialized server for ${host}`);
177
- }
178
- }
179
-
180
- // Retornar los servidores para iniciarlos después
181
- return { httpsServer, httpServer };
182
- }
183
-
184
163
  start() {
185
164
  this.loadSites();
186
165
  this.generateConfigJson();
@@ -193,26 +172,31 @@ class Roster {
193
172
  staging: this.staging
194
173
  });
195
174
 
196
- // Usar una promesa para manejar la inicialización
197
- return new Promise((resolve, reject) => {
198
- try {
199
- greenlock.ready((glx) => {
200
- const { httpsServer, httpServer } = this.initServers(glx);
201
-
202
- // Primero iniciar el servidor HTTPS
203
- httpsServer.listen(this.port, '0.0.0.0', () => {
204
- console.log('ℹ️ HTTPS server listening on port ' + this.port);
205
-
206
- // Después iniciar el servidor HTTP
207
- httpServer.listen(80, '0.0.0.0', () => {
208
- console.log('ℹ️ HTTP server listening on port 80');
209
- resolve({ httpsServer, httpServer });
210
- });
211
- });
212
- });
213
- } catch (error) {
214
- reject(error);
175
+ const app = (req, res) => {
176
+ this.handleRequest(req, res);
177
+ };
178
+
179
+ greenlock.ready(glx => {
180
+ // Obtener los servidores sin iniciarlos
181
+ const httpsServer = glx.httpsServer(null, app);
182
+ const httpServer = glx.httpServer();
183
+
184
+ for (const [host, siteApp] of Object.entries(this.sites)) {
185
+ if (!host.startsWith('www.')) {
186
+ const appInstance = siteApp(httpsServer);
187
+ this.sites[host] = appInstance;
188
+ this.sites[`www.${host}`] = appInstance;
189
+ console.log(`🔧 Initialized server for ${host}`);
190
+ }
215
191
  }
192
+
193
+ httpServer.listen(80, this.hostname, () => {
194
+ console.log('ℹ️ HTTP server listening on port 80');
195
+ });
196
+
197
+ httpsServer.listen(this.port, this.hostname, () => {
198
+ console.log('ℹ️ HTTPS server listening on port ' + this.port);
199
+ });
216
200
  });
217
201
  }
218
202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roster-server",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "👾 RosterServer - A domain host router to host multiple HTTPS.",
5
5
  "main": "index.js",
6
6
  "scripts": {