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 🙏

© 2025 – Pkg Stats / Ryan Hefner

smart-relay

v1.1.2

Published

A simple HTTP proxy server that forwards requests to a destination specified in the 'x-destination-url' header

Readme

HTTP Proxy Server

A simple HTTP proxy server that forwards requests to a destination specified in the 'x-destination-url' header. It supports both HTTP and HTTPS protocols.

If you find this project helpful, you can support the author by making a donation:

Installation

Usage

As a standalone server

  1. Start the server:

    npx smart-relay
  2. The server will listen on port 8080 by default.

  3. To use the proxy, make HTTP requests to the server with the x-destination-url header set to the target URL.

    Example using curl:

    curl -H "x-destination-url: https://example.com" http://localhost:8080/path

Using Cloudflare Tunnel for Public Access

The server can also create a Cloudflare tunnel to expose your local server to the internet.

Prerequisites:

  • You must have the cloudflared CLI tool installed on your system. You can download it from the Cloudflare website.
  • The cloudflared command must be available in your system's PATH.

Note: The server will automatically check if a tunnel named "smart-relay" exists. If it doesn't exist, it will create it (this is a one-time operation). If the tunnel already exists, it will skip the creation step and directly run the tunnel.

  1. Enable a Cloudflare tunnel in the configuration file at ~/.smart-relay/config.json:

    {
      "PORT": 8080,
      "CLOUDFLARE_ENABLED": true
    }
  2. Or use environment variables:

    CLOUDFLARE_ENABLED=true npx smart-relay
  3. When the server starts with Cloudflare tunnel enabled, it will display the public URL that can be used to access your proxy server from anywhere.

Note: You need to have Cloudflare CLI installed and authenticated to use this feature.

Using Ngrok for Public Access

The server can automatically create a ngrok tunnel to expose your local server to the internet.

Prerequisites:

  • You must have the ngrok CLI tool installed on your system. You can download it from the ngrok website.
  • The ngrok command must be available in your system's PATH.
  1. Enable ngrok in the configuration file at ~/.smart-relay/config.json:

    {
      "PORT": 8080,
      "NGROK_ENABLED": true,
      "NGROK_TOKEN": "your-ngrok-token",
      "NGROK_REGION": "us"
    }
  2. Or use environment variables:

    NGROK_ENABLED=true NGROK_TOKEN=your-ngrok-authtoken npx smart-relay
  3. When the server starts with ngrok enabled, it will display the public URL that can be used to access your proxy server from anywhere.

Note: While an auth token is not strictly required, ngrok has limitations for unauthenticated tunnels. Get your free auth token by signing up at ngrok.com.

Using Callback URL for Tunnel Notification

The server can notify an external service when a tunnel URL is available by sending a POST request to a specified callback URL. This is useful for integrating with other systems that need to know the public URL of your tunnel.

  1. Configure the callback URL and optional authentication header in the configuration file at ~/.smart-relay/config.json:

    {
      "PORT": 8080,
      "NGROK_ENABLED": true,
      "CALLBACK_URL": "https://your-api.example.com/webhook",
      "CALLBACK_AUTH_HEADER": "Bearer your-auth-token",
      "CALLBACK_INTERVAL": 10000
    }
  2. Or use environment variables:

    NGROK_ENABLED=true CALLBACK_URL=https://your-api.example.com/webhook CALLBACK_AUTH_HEADER="Bearer your-auth-token" CALLBACK_INTERVAL=10000 npx smart-relay
  3. When a tunnel is established (either ngrok or Cloudflare), the server will send a POST request to the callback URL with the tunnel URL in JSON format:

    {
      "tunnelUrl": "https://your-tunnel-url.ngrok.io"
    }
  4. The server will continue to send this request periodically (every 10 seconds by default) to ensure the tunnel is online. You can customize the interval by setting the CALLBACK_INTERVAL parameter (in milliseconds).

Note: This feature is designed to notify an external service about the public tunnel URL and to keep the tunnel active by making regular calls to the external API.

Error Handling

The server handles various error scenarios:

| Error scenario | Error code | |--------------------------------|------------| | Missing destination URL header | 001 | | Proxy request failures | 002 |