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

@namatery/blackbird

v1.0.3

Published

Blackbird is a reverse proxy, with built-in node cluster and load balancing.

Downloads

6

Readme

Blackbird

Blackbird is a reverse proxy, with built-in node cluster and load balancing.

Installation

To install Blackbird you can easily run below command:

npm i @namatery/blackbird

How to use Blackbird?

First of all, create a proxy server like below:

const proxy = new ReversProxy({
  http: {
    port: 3000,
  },
});

NOTE: http.port is required.

Registering

To register a domain, do like this:

proxy.register({
  source: 'http://localhost:3000/',
  target: 'http://test.com/',
  opts: {
    redirect: false,
    ws: false,
  },
});

Options

  • source [required]: The url that client make a request to it.
  • target [required]: The url that if client makes a reqeust to source, Blackbird redirects the request to it.
  • redirect [optional]: If set true, Blackbird automatically redirects to HTTPS.
  • ws [optional]: If set true, Blackbird allows clients to make socket connection.

Notice

  • You can set several target for a single source.
  • Before set redirect as true, make sure you have configured proxy for HTTPS requests.
  • For load balancing, Blackbird uses round-robin algorithm.

Enable HTTPS

To enable HTTPS, you can pass creditions like below:

const proxy = new ReversProxy({
  http: {
    port: 3000,
  },
  https: {
    port: 9000,
    cert: 'path/to/cert.pem',
    key: 'path/to/key.pem',
    ca: 'path/to/ca.pem',
  },
});

NOTE 1: port is required.

NOTE 2: cert, key and ca can be buffers. (ca is optional)

In the above example, the creditoins that we set wil use for all registerd domain, but you can also attach the creditions for a specifyed domain.

proxy.attachSSL({
  hostname: 'localhost:3000',
  cert: 'path/to/cert.pem',
  key: 'path/to/key.pem',
  ca: 'path/to/ca.pem',
});

NOTE 1: hostname is the hostname that we registerd as source above as you saw.

NOTE 2: You can't attach several creditions for a single hostname.

How to run our proxy?

To start proxy, you have two options. You can either run it in the normal way like below:

proxy.start();

Or run it in the cluster mode like below:

proxy.startCluster(3);

In this case Blackbird will run three instances of our proxy. To learn more about cluster in nodejs go to node-cluster.

Does Blackbird handle CORS in its own?

Yes! Blackbird uses Express Cors package to handle this concept and you can enable it like below:

const proxy = new ReversProxy({
  http: {
    port: 3000,
  },
  cors: {
    origin: 'http://localhost:3000/'
  }
});

NOTE 1: All the options is similar with Express Cors package.

TODOs

  • [x] Writing Unite test for Table repository.
  • [x] Writing Unite test for SSL repository.
  • [ ] CORS error on redirecting from http to https.
  • [ ] CORS error on websocket communication.
  • [ ] Writing Unite test for proxy class.