npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

roster-server

v1.4.4

Published

👾 RosterServer - A domain host router to host multiple HTTPS.

Downloads

235

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:

  1. 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á."');
    };
};
  1. 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;
}
  1. 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 your www directory containing your sites.
  • greenlockConfigDir (string): Directory for Greenlock configuration.
  • staging (boolean): Set to true 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! 🎈