roster-server
Version:
š¾ RosterServer - A domain host router to host multiple HTTPS.
37 lines (28 loc) ⢠1.31 kB
JavaScript
const Roster = require('../index.js');
// Example: Get URL after registration (adapts to environment)
console.log('\nš§ Creating local development server...\n');
const roster = new Roster({ local: true });
roster.register('example.com', (httpsServer) => {
return (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from example.com!');
};
});
roster.register('api.example.com', (httpsServer) => {
return (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'API endpoint' }));
};
});
roster.start().then(() => {
console.log('š Server Started - URLs (based on environment):');
console.log('example.com ā', roster.getUrl('example.com'));
console.log('api.example.com ā', roster.getUrl('api.example.com'));
// Test with www prefix (should return same URL)
console.log('\nš Testing www prefix handling:');
console.log('www.example.com ā', roster.getUrl('www.example.com'));
// Test non-existent domain
console.log('\nā Testing non-existent domain:');
console.log('nonexistent.com ā', roster.getUrl('nonexistent.com') || 'null (domain not registered)');
console.log('\nā
All domains running!');
});