roster-server 1.8.0 → 1.8.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/demo/roster/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module.exports = (httpsServer) => {
|
|
2
2
|
return (req, res) => {
|
|
3
3
|
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
4
|
-
res.end('"Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
|
|
4
|
+
res.end('"example.com: Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
|
|
5
5
|
};
|
|
6
6
|
};
|
|
@@ -4,7 +4,7 @@ module.exports = (httpsServer) => {
|
|
|
4
4
|
const app = express();
|
|
5
5
|
app.get('/', (req, res) => {
|
|
6
6
|
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
7
|
-
res.send('"Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
|
|
7
|
+
res.send('"subdomain.example.com: Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
return app;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module.exports = (httpsServer) => {
|
|
2
2
|
return (req, res) => {
|
|
3
3
|
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
4
|
-
res.end('"
|
|
4
|
+
res.end('"subdomain.example.com: Crazy from thinking, wanting to be reasonable, and the heart has reasons that reason itself will never understand."');
|
|
5
5
|
};
|
|
6
6
|
};
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const http = require('http');
|
|
3
4
|
const https = require('https');
|
|
4
5
|
const tls = require('tls');
|
|
5
6
|
const { EventEmitter } = require('events');
|
|
@@ -79,6 +80,7 @@ class Roster {
|
|
|
79
80
|
this.greenlockStorePath = options.greenlockStorePath || path.join(basePath, 'greenlock.d');
|
|
80
81
|
this.staging = options.staging || false;
|
|
81
82
|
this.cluster = options.cluster || false;
|
|
83
|
+
this.local = options.local || false; // New local mode option
|
|
82
84
|
this.domains = [];
|
|
83
85
|
this.sites = {};
|
|
84
86
|
this.domainServers = {}; // Store separate servers for each domain
|
|
@@ -87,7 +89,7 @@ class Roster {
|
|
|
87
89
|
this.filename = options.filename || 'index';
|
|
88
90
|
|
|
89
91
|
const port = options.port === undefined ? 443 : options.port;
|
|
90
|
-
if (port === 80) {
|
|
92
|
+
if (port === 80 && !this.local) {
|
|
91
93
|
throw new Error('⚠️ Port 80 is reserved for ACME challenge. Please use a different port.');
|
|
92
94
|
}
|
|
93
95
|
this.defaultPort = port;
|
|
@@ -277,7 +279,7 @@ class Roster {
|
|
|
277
279
|
if (parts.length === 2) {
|
|
278
280
|
const domain = parts[0];
|
|
279
281
|
const port = parseInt(parts[1]);
|
|
280
|
-
if (port === 80) {
|
|
282
|
+
if (port === 80 && !this.local) {
|
|
281
283
|
throw new Error('⚠️ Port 80 is reserved for ACME challenge. Please use a different port.');
|
|
282
284
|
}
|
|
283
285
|
return { domain, port };
|
|
@@ -307,9 +309,72 @@ class Roster {
|
|
|
307
309
|
return null;
|
|
308
310
|
}
|
|
309
311
|
|
|
312
|
+
// Start server in local mode with HTTP - simplified version
|
|
313
|
+
startLocalMode() {
|
|
314
|
+
const startPort = 3000;
|
|
315
|
+
let currentPort = startPort;
|
|
316
|
+
|
|
317
|
+
// Create a simple HTTP server for each domain with sequential ports
|
|
318
|
+
for (const [hostKey, siteApp] of Object.entries(this.sites)) {
|
|
319
|
+
const domain = hostKey.split(':')[0]; // Remove port if present
|
|
320
|
+
|
|
321
|
+
// Skip www domains in local mode
|
|
322
|
+
if (domain.startsWith('www.')) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const port = currentPort; // Capture current port value
|
|
327
|
+
|
|
328
|
+
// Create virtual server for the domain
|
|
329
|
+
const virtualServer = this.createVirtualServer(domain);
|
|
330
|
+
this.domainServers[domain] = virtualServer;
|
|
331
|
+
|
|
332
|
+
// Initialize app with virtual server
|
|
333
|
+
const appHandler = siteApp(virtualServer);
|
|
334
|
+
|
|
335
|
+
// Create simple dispatcher for this domain
|
|
336
|
+
const dispatcher = (req, res) => {
|
|
337
|
+
if (virtualServer.requestListeners.length > 0) {
|
|
338
|
+
virtualServer.processRequest(req, res);
|
|
339
|
+
} else if (appHandler) {
|
|
340
|
+
appHandler(req, res);
|
|
341
|
+
} else {
|
|
342
|
+
res.writeHead(404);
|
|
343
|
+
res.end('Site not found');
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// Create HTTP server for this domain
|
|
348
|
+
const httpServer = http.createServer(dispatcher);
|
|
349
|
+
this.portServers[port] = httpServer;
|
|
350
|
+
|
|
351
|
+
httpServer.listen(port, 'localhost', () => {
|
|
352
|
+
console.log(`🌐 ${domain} → http://localhost:${port}`);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
httpServer.on('error', (error) => {
|
|
356
|
+
console.error(`❌ Error on port ${port} for ${domain}:`, error.message);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
currentPort++;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
console.log(`✅ Started ${currentPort - startPort} sites in local mode`);
|
|
363
|
+
return Promise.resolve();
|
|
364
|
+
}
|
|
365
|
+
|
|
310
366
|
async start() {
|
|
311
367
|
await this.loadSites();
|
|
312
|
-
|
|
368
|
+
|
|
369
|
+
// Skip Greenlock configuration generation in local mode
|
|
370
|
+
if (!this.local) {
|
|
371
|
+
this.generateConfigJson();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// Handle local mode with simple HTTP server
|
|
375
|
+
if (this.local) {
|
|
376
|
+
return this.startLocalMode();
|
|
377
|
+
}
|
|
313
378
|
|
|
314
379
|
const greenlock = Greenlock.init({
|
|
315
380
|
packageRoot: __dirname,
|
|
@@ -431,7 +496,10 @@ class Roster {
|
|
|
431
496
|
});
|
|
432
497
|
|
|
433
498
|
httpsServer.on('tlsClientError', (error) => {
|
|
434
|
-
|
|
499
|
+
// Suppress HTTP request errors to avoid log spam
|
|
500
|
+
if (!error.message.includes('http request')) {
|
|
501
|
+
console.error(`TLS error on port ${portNum}:`, error.message);
|
|
502
|
+
}
|
|
435
503
|
});
|
|
436
504
|
|
|
437
505
|
this.portServers[portNum] = httpsServer;
|