roster-server 1.4.8 → 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.
- package/index.js +27 -43
- 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 = ['
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
}
|