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

nano-gateway

v1.1.0

Published

Lightweight API gateway for home-scale projects

Downloads

12

Readme

nano-gateway

NPM version Build status Node version Docker Hub XO code style License

Lightweight API gateway for home-scale projects.

Features:

  • Single-file YAML configuration
  • HTTPS support
  • Secure endpoints with API key
  • URL rewriting
  • Less than 60 LOC :smile:

Installation

npm install -g nano-gateway

Usage

Usage: nanog [--config file.yml] [--keygen]

Use the nanog command to start the gateway.

By default, it will use the config.yml configuration in the current working directory, but any file can be specified using either the NANO_GATEWAY_CONFIG environment variable or the --config option.

The --keygen will generate a suitable API key to use in your configuration.

Configuration

Here is an example config.yml configuration:

http:                 # optional, enable HTTP gateway
  port: 8080          # optional, specify port for HTTP (default is 8080)
https:                # optional, enable HTTPS gateway
  cert: 'cert.pem'    # required, certificate path
  key: 'privkey.pem'  # required, private key path
  ca: 'chain.pem'     # optional, override trusted CA certificates
  port: 8443          # optional, specify port for HTTPS (default is 8443)
auth: true            # optional, enable API key authorization by default for all services
apiKey: '123456'      # required if auth is enabled, use nanog --keygen to generate a new key
services:             # required, define here the services to proxify
  ip:                           # required, service name
    path: '/ip'                 # required, endpoint(s) (use Express route syntax, see npmjs.com/path-to-regexp)
    url: 'https://httpbin.org'  # required, target url for
    auth: false                 # optional, authorization can be set or overriden by service
  quote:                        # another service, add as many as you need
    path: '/jokes/*'            # matches any routes under /jokes/
    rewrite: '/jokes/random'    # optional, rewrite URL (for syntax, see npmjs.com/express-urlrewrite)
    url: 'https://api.chucknorris.io'

API key

Endpoints secured by API key can be consumed either by using an apiKey query parameter:

curl https://gateway.com/endpoint?apiKey=<your_api_key>

or by using an Authorization header:

curl -H "Authorization: <your_api_key>" https://gateway.com/endpoint

Note: It is strongly recommended to use only HTTPS with API keys, otherwise your credentials will circulate in clear over the network and may be intercepted.

HTTPS

To enable HTTPS you need a valid SSL certificate.

Free LetsEncrypt certificates can be obtained using certbot.

For testing purposes, you can also generate a self-signed certificate using this command:

openssl req -nodes -new -x509 -keyout privkey.pem -out cert.pem

After you have your certificate, use it in your configuration like this:

https:
  cert: 'cert.pem'
  key: 'privkey.pem'
  ca: 'chain.pem' # optional, override trusted CA certificates

Running on Docker

A minimal Docker image based on node:alpine is also available for deployment.

You just need to map a folder with a config.yml file in it to the /config volume:

docker pull sinedied/nano-gateway
docker run --d -v <your_config_dir>:/config -p 8443:8443 --name nano-gateway sinedied/nano-gateway