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

@cloud-cli/proxy

v1.5.0

Published

HTTP(S) Proxy server

Downloads

43

Readme

@cloud-cli/proxy

HTTP(S) Proxy server

Settings

certificatesFolder:

The server automatically loads SSL certificates from a folder, where each subfolder is a domain name. Sub-domains are automatically resolved to their parent domain when requested. sub.example.com will use the certificate from example.com if available.

For example, to load certs for *.foo.com and *.example.com:

const settings = new ProxySettings({
  certificatesFolder: '/var/ssl',
  certificateFile: 'cert.pem',
  keyFile: 'cert.key',
});
$ ls /var/ssl/*

/var/ssl/foo.com:
cert.pem
cert.key

/var/ssl/example.com:
cert.pem
cert.key

certificateFile/keyFile:

Names of the files from where certificates are loaded.

Defaults:

const settings = new ProxySettings({
  certificateFile = 'fullchain.pem';
  keyFile = 'privkey.pem';
});

httpPort/httpsPort:

Allow you to change the http ports. Defaults are 80 and 443

const settings = new ProxySettings({
  httpPort: 3000,
  httpsPort: 3443,
});

headers:

Adds headers to the proxy request transparently, so API calls can be proxied without exposing credentials.

Use key/value pairs separated by a bar. Spaces around are ignored.

Example authentication: bearer abc123 | x-custom-header: 123

Usage

import { ProxyServer, ProxySettings, ProxyEntry } from '@cloud-cli/proxy';

// set up the proxy instance
const settings = new ProxySettings({ ... });

// create a server
const server = new ProxyServer(settings);

// create internal HTTP/HTTPS servers
server.createServers();

// start HTTP/HTTPS servers
server.start();

// add a proxy entry
server.add(new ProxyEntry({...}));

// use it to reset all proxy entries and close running HTTP ports
server.reset();

// reload certificates for all proxy entries.
// each server reloads all certificates once per day
server.reload();

// OPTIONAL: handle a request coming from another http(s) server
server.handleRequest(request, response, /* isSSL */ false);

Example

import { ProxyServer, ProxySettings, ProxyEntry } from '@cloud-cli/proxy';

const settings = new ProxySettings({
  certificatesFolder: '/path/to/ssl',
});

const server = new ProxyServer(settings);
server.start();

// http://example.com => (redirect 302) https://www.example.com/
server.add(
  new ProxyEntry({
    domain: 'example.com',
    redirectToDomain: 'www.example.com',
  }),
);

// http://old.example.com => (redirect 302) https://www.example.com/
server.add(
  new ProxyEntry({
    domain: 'old.example.com',
    redirectToUrl: 'https://www.example.com/',
  }),
);

// http://www.example.com => (forward to) http://localhost:1234/
server.add(
  new ProxyEntry({
    domain: 'www.example.com',
    target: 'http://localhost:1234/',
  }),
);

Environment variables

| var | description | | ------------------ | -------------------------------------------------- | | DEBUG | Enable debug logging | | PROXY_CERTS_FOLDER | Path to a folder where SSL certificates are stored | | HTTP_PORT | Number. Same as ProxySettings#httpPort | | HTTPS_PORT | Number. Same as ProxySettings#httpsPort |

http-proxy

This module also provides an executable to run as a standalone server.

Options can be either provided as a JSON file (proxy.config.json) or an ES module (proxy.config.mjs). The format is defined in src/cli.mts. It is the same as ProxySettings + an array of ProxyEntry;

To run the proxy, just call http-proxy in the same folder as the configuration file:

$ http-proxy

Full configuration

{
  "httpPort": 80,
  "httpsPort": 443,
  "autoReload": 3600,
  "certificatesFolder": "/etc/ssl",
  "certificateFile": "fullchain.pem",
  "keyFile": "privkey.pem",
  "proxies": [
    {
      "domain": "example.com",
      "redirectToDomain": "www.example.com"
    },
    {
      "domain": "old.example.com",
      "redirectToUrl": "https://www.example.com"
    },
    {
      "domain": "www.example.com",
      "headers": "x-key: deadbeef",
      "target": "http://localhost:1234/"
    }
  ]
}