roster-server
v1.4.4
Published
👾 RosterServer - A domain host router to host multiple HTTPS.
Downloads
235
Maintainers
Readme
👾 RosterServer
Because hosting multiple HTTPS sites has never been easier!
Welcome to RosterServer, the ultimate domain host router with automatic HTTPS and virtual hosting. Why juggle multiple servers when you can have one server to rule them all? 😉
✨ Features
- Automatic HTTPS with Let's Encrypt via Greenlock.
- Dynamic Site Loading: Just drop your Node.js apps in the
www
folder. - Virtual Hosting: Serve multiple domains from a single server.
- Automatic Redirects: Redirect
www
subdomains to the root domain. - Zero Configuration: Well, almost zero. Just a tiny bit of setup.
📦 Installation
npm install roster-server
🛠️ Usage
Directory Structure
Your project should look something like this:
/srv/
├── greenlock.d/
├── roster/server.js
└── www/
├── example.com/
│ └── index.js
└── subdomain.example.com/
└── index.js
Setting Up Your Server
// /srv/roster/server.js
const Roster = require('roster-server');
const options = {
maintainerEmail: '[email protected]',
greenlockConfigDir: '/srv/greenlock.d', // Path to your Greenlock configuration directory
wwwPath: '/srv/www', // Path to your 'www' directory (default: '../www')
staging: false // Set to true for Let's Encrypt staging environment
};
const server = new Roster(options);
server.start();
Your Site Handlers
Each domain should have its own folder under www
, containing an index.js
that exports a request handler function.
Examples
I'll help analyze the example files shown. You have 3 different implementations demonstrating various ways to handle requests in RosterServer:
- Basic HTTP Handler:
module.exports = (httpsServer) => {
return (req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end('"Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
};
};
- Express App:
const express = require('express');
module.exports = (httpsServer) => {
const app = express();
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.send('"Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
});
return app;
}
- Socket.IO Server:
const { Server } = require('socket.io');
module.exports = (httpsServer) => {
const io = new Server(httpsServer);
io.on('connection', (socket) => {
console.log('A user connected');
socket.on('chat:message', (msg) => {
console.log('Message received:', msg);
io.emit('chat:message', msg);
});
socket.on('disconnect', () => {
console.log('User disconnected');
});
});
return (req, res) => {
res.writeHead(200);
res.end('Socket.IO server running');
};
};
Running the Server
# /srv/roster/server.js
node server.js
And that's it! Your server is now hosting multiple HTTPS-enabled sites. 🎉
🤯 But Wait, There's More!
Automatic SSL Certificate Management
RosterServer uses greenlock-express to automatically obtain and renew SSL certificates from Let's Encrypt. No need to manually manage certificates ever again. Unless you enjoy that sort of thing. 🧐
Redirects from www
All requests to www.yourdomain.com
are automatically redirected to yourdomain.com
. Because who needs the extra three characters? 😏
Dynamic Site Loading
Add a new site? Just drop it into the www
folder with an index.js
file, and RosterServer will handle the rest. No need to restart the server. Well, you might need to restart the server. But that's what nodemon
is for, right? 😅
⚙️ Configuration Options
When creating a new RosterServer
instance, you can pass the following options:
maintainerEmail
(string): Your email for Let's Encrypt notifications.wwwPath
(string): Path to yourwww
directory containing your sites.greenlockConfigDir
(string): Directory for Greenlock configuration.staging
(boolean): Set totrue
to use Let's Encrypt's staging environment (for testing).
🧂 A Touch of Magic
You might be thinking, "But setting up HTTPS and virtual hosts is supposed to be complicated and time-consuming!" Well, not anymore. With RosterServer, you can get back to writing code that matters, like defending Earth from alien invaders! 👾👾👾
🤝 Contributing
Feel free to submit issues or pull requests. Or don't. I'm not your boss. 😜
If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.
🙏 Acknowledgments
📄 License
The MIT License (MIT)
Copyright (c) Martin Clasen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Happy hosting! 🎈