roster-server 2.4.11 → 2.4.12
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 +3 -2
- package/package.json +1 -1
- package/test/roster-server.test.js +45 -0
package/index.js
CHANGED
|
@@ -322,6 +322,7 @@ class Roster {
|
|
|
322
322
|
return;
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
+
const siteKeyForDomain = (domain) => this.defaultPort === 443 ? domain : `${domain}:443`;
|
|
325
326
|
const sites = fs.readdirSync(this.wwwPath, { withFileTypes: true })
|
|
326
327
|
.filter(dirent => dirent.isDirectory());
|
|
327
328
|
|
|
@@ -350,7 +351,7 @@ class Roster {
|
|
|
350
351
|
continue;
|
|
351
352
|
}
|
|
352
353
|
this.domains.push(domain);
|
|
353
|
-
this.sites[domain] = siteApp;
|
|
354
|
+
this.sites[siteKeyForDomain(domain)] = siteApp;
|
|
354
355
|
const root = wildcardRoot(domain);
|
|
355
356
|
if (root) this.wildcardZones.add(root);
|
|
356
357
|
log.info(`(✔) Loaded wildcard site: https://${domain}${type === 'static' ? ' (static)' : ''}`);
|
|
@@ -358,7 +359,7 @@ class Roster {
|
|
|
358
359
|
const domainEntries = [domain, `www.${domain}`];
|
|
359
360
|
this.domains.push(...domainEntries);
|
|
360
361
|
domainEntries.forEach(d => {
|
|
361
|
-
this.sites[d] = siteApp;
|
|
362
|
+
this.sites[siteKeyForDomain(d)] = siteApp;
|
|
362
363
|
});
|
|
363
364
|
log.info(`(✔) Loaded site: https://${domain}${type === 'static' ? ' (static)' : ''}`);
|
|
364
365
|
}
|
package/package.json
CHANGED
|
@@ -513,6 +513,51 @@ describe('Roster local mode (local: true)', () => {
|
|
|
513
513
|
});
|
|
514
514
|
|
|
515
515
|
describe('Roster loadSites', () => {
|
|
516
|
+
it('keeps discovered sites on 443 when the same domain is registered on other ports', async () => {
|
|
517
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'roster-test-'));
|
|
518
|
+
const wwwPath = path.join(tmpDir, 'www');
|
|
519
|
+
const siteDir = path.join(wwwPath, 'persist.example.com');
|
|
520
|
+
fs.mkdirSync(siteDir, { recursive: true });
|
|
521
|
+
fs.writeFileSync(path.join(siteDir, 'index.html'), '<html>static-443</html>', 'utf8');
|
|
522
|
+
|
|
523
|
+
const roster = new Roster({ wwwPath, local: true, port: 8880 });
|
|
524
|
+
roster.register('persist.example.com', () => (req, res) => {
|
|
525
|
+
res.writeHead(200);
|
|
526
|
+
res.end('app-8880');
|
|
527
|
+
});
|
|
528
|
+
roster.register('persist.example.com:8882', () => (req, res) => {
|
|
529
|
+
res.writeHead(200);
|
|
530
|
+
res.end('socket-8882');
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
try {
|
|
534
|
+
await roster.init();
|
|
535
|
+
|
|
536
|
+
const dispatch = (port) => {
|
|
537
|
+
let statusCode;
|
|
538
|
+
let body = '';
|
|
539
|
+
const res = {
|
|
540
|
+
writeHead: (status) => { statusCode = status; },
|
|
541
|
+
end: (value) => { body = value ? value.toString() : ''; }
|
|
542
|
+
};
|
|
543
|
+
roster.requestHandler(port)(
|
|
544
|
+
{ headers: { host: 'persist.example.com' }, method: 'GET', url: '/' },
|
|
545
|
+
res
|
|
546
|
+
);
|
|
547
|
+
return { statusCode, body };
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
assert.deepStrictEqual(dispatch(443), {
|
|
551
|
+
statusCode: 200,
|
|
552
|
+
body: '<html>static-443</html>'
|
|
553
|
+
});
|
|
554
|
+
assert.deepStrictEqual(dispatch(8880), { statusCode: 200, body: 'app-8880' });
|
|
555
|
+
assert.deepStrictEqual(dispatch(8882), { statusCode: 200, body: 'socket-8882' });
|
|
556
|
+
} finally {
|
|
557
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
|
|
516
561
|
it('loads site from www directory and registers domain + www', async () => {
|
|
517
562
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'roster-test-'));
|
|
518
563
|
const wwwPath = path.join(tmpDir, 'www');
|