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

proxyok

v2.1.2

Published

This module creates a basic proxy server which replies with 200 OK Status code to all the http requests.

Downloads

4

Readme

ProxyOK

This module creates a basic proxy server which replies with 200 OK Status code to all the http requests.

Install

npm i proxyok

How to use

It is possible to:

  1. let ProxyOK to create the HTTP local server for you (you can specify the port on localhost to listen for)
  2. using proxyok.onRequest method as middleware for http server created by you

In both cases, you can:

  • set a predefined remote domain to forward the all the requests
  • keep the proxy "generic" and forward requests depending on the url parameter.

1) Let ProxyOK to create the HTTP local server for you

In this way the module auto-creates the server at http://localhost:9000/ and every request will be forwarded to https://npmjs.com/*:

STATIC ENDPOINT EXAMPLE

var http = require('http');
var proxyok = require("proxyok");
proxyok({
    port: 9000,
    endpoint: {
        //protocol: 'https:', // default is https:
        hostname: 'npmjs.com',
        port: 443
    }
});

Example: $ node ./examples/with-server/generic-per-request/proxy-per-request.js then type in your browsers address bar: http://localhost:9000/package/proxyok

2) Create your own server and use ProxyOK as middleware

You have to set autostart option as boolean false value. In this way you can use your own HTTP server with proxyok.onRequest method for handle the requests:

GENERIC REQUEST EXAMPLE

const http = require('http'),
    proxyok = require("proxyok")({
        autostart: false,
        endpoint: {
            //protocol: 'https:', // default is https:
            hostname: 'npmjs.com',
            port: 443
        }
    }),
    server_port = process.env.PORT || 8082,
    server = http.createServer(proxyok.onRequest);

server.listen(server_port, (err) => {
    if (err) {
        throw err;
    } else {
        console.log('Server listening on port ' + server_port);
    }
}).on('error', console.error);

Example: $ node ./examples/as-middleware/localhost_8082_generic-request.js then type in your browsers address bar: http://localhost:8082?url=https://npmjs.ord/package/proxyok

a. Define a remote domain

a.1 - With environment variables file - with server autostart

In this case .env file has been placed in the app root directory.

NODE_TLS_REJECT_UNAUTHORIZED=0

PROXYOK_PORT=8080
PROXYOK_ENDPOINT_PROTOCOL=https:
PROXYOK_ENDPOINT_HOSTNAME=remotedomain.example.com
PROXYOK_ENDPOINT_PORT=443
const proxyok = require('proxyok')
proxyok({
    envpath: __dirname + '/.env' // it could be any valid file path
});

a.2 - With environment variables file - through external HTTP server

In this case .env file has been placed in the app root directory.

NODE_TLS_REJECT_UNAUTHORIZED=0
PORT=8080

PROXY_OK_AUTOSTART=false
PROXYOK_ENDPOINT_PROTOCOL=https:
PROXYOK_ENDPOINT_HOSTNAME=remotedomain.example.com
PROXYOK_ENDPOINT_PORT=443
const http = require('http')
    , proxyok = require('proxyok')({
        envpath: __dirname + '/.env' // it could be any valid file path
    })
    , server_port = process.env.PORT || 8080,
    , server = http.createServer(proxyok.onRequest)

server.listen(server_port, (err) => {
    if (err) {
        throw err;
    } else {
        console.log('Server listening on port ' + server_port);
    }
}).on('error', console.error);

The proxy server will listen at http://localhost:8080 and all the requests will be forwarded to https://remotedomain.example.com. Example: http://localhost:8080/webpage.html will retrieve the resource from https://remotedomain.example.com/webpage.html with status code 200 OK.

a.3 - Providing options - with server autostart

const proxyok = require('proxyok');
proxyok({
	port: 9000,
	endpoint: {
		//protocol: 'https:', // default is https:
		hostname: 'remotedomain.example.com',
		port: 443
	}
});

a.4 - Providing options - through external HTTP server

const const http = require('http')
    , proxyok = require('proxyok')({
        autostart: false,
        endpoint: {
            //protocol: 'https:', // default is https:
            hostname: 'remotedomain.example.com',
            port: 443
        }
    })
    , server_port = process.env.PORT || 9000
    , server = http.createServer(proxyok.onRequest);

server.listen(server_port, (err) => {
    if (err) {
        throw err;
    } else {
        console.log('Server listening on port ' + server_port);
    }
}).on('error', console.error);

The proxy server will listen at http://localhost:9000 and all the requests will be forwarded to https://remotedomain.example.com. Example: http://localhost:8080/webpage.html will retrieve the resource from https://remotedomain.example.com/webpage.html with status code 200 OK.

b - Generic remote host

b.1 - Via url parameter - with server autostart

const proxyok = request('proxyok');
proxyok({
	port: 8082,
	generic: true
});

b.2- Via url parameter - through external HTTP server

const http = require('http')
    , proxyok = require('proxyok')({
        autostart: false,
	    generic: true
    })
    , server_port = process.env.PORT || 8082
    , server = http.createServer(proxyok.onRequest);

server.listen(server_port, (err) => {
    if (err) {
        throw err;
    } else {
        console.log('Server listening on port ' + server_port);
    }
}).on('error', console.error);

The proxy server will listen at http://localhost:8082?url=[...]. All the requests will be forwarded to the specified url parameter. Example: http://localhost:8082?url=https://remotedomain.example.com/urlwebpage.html will retrieve the resource from https://remotedomain.example.com/webpage.html with status code 200 OK.

Valid javascript options

var options = {
    envpath, // {string} Path of the evnironment variables
    autostart, // {bool} If true, the proxy will automatically create an HTTP server that listens for requests. Default is true (for backward compatibility).
    port, // {int} Port the server will listen for at localhost
    generic, // {bool} If true, the proxy will act as hostname agnostic
    auth: {
        check, // {bool} If true, the proxy will match the provided auth with the ones coming from request's "Authorization" header
        override, // {bool} If true, the app will build auth token (with given token or by username, password and type) and provides it to the proxied request as "Authorization" header
        type, // {string} If provided: basic, bearer
        username,
        password,
        token, // {string} If provided, it will be used as double-check or for authorizaion header overriding
    },
    endpoint: {
        protocol,
        username,
        password,
        hostname,
        port
    }
}

Valid environment variables

Place your own values after = symbols and/or remove unused ones.

PROXYOK_AUTOSTART=[false|true|0|1]
PROXYOK_PORT=8080
PROXYOK_AUTH_USERNAME=headerAuthUser
PROXYOK_AUTH_PASSWORD=headerAuthPassword
PROXYOK_AUTH_TYPE=basic
PROXYOK_AUTH_CHECK=true
PROXYOK_AUTH_OVERRIDE=false
PROXYOK_AUTH_TOKEN=PlaceYourBasicAuthorizationTokenHere
PROXYOK_ENDPOINT_PROTOCOL=https:
PROXYOK_ENDPOINT_USERNAME=endpointInlineUsername
PROXYOK_ENDPOINT_PASSWORD=endpointInlinePassword
PROXYOK_ENDPOINT_HOSTNAME=example.remotedomain.com
PROXYOK_ENDPOINT_PORT=443

With the above process.env[...] variables:

  • The proxy server listens at http://localhost:8080
  • All the requests (when properly authorized - see next points) will be forwarded to https://endpointInlineUsername:[email protected]:443
  • It forwards Authorization header like: Authorization: Basic PlaceYourBasicAuthorizationTokenHere
  • The client must provide Authorization header and there must be an exact match with the one set with this .env file. Otherwise the request will not be proxied.
  • PROXYOK_AUTH_USERNAME, PROXYOK_AUTH_PASSWORD, PROXYOK_AUTH_TYPE can be omitted (since they will be ignored) when providing PROXYOK_AUTH_TOKEN

Notes:

  • When setting PROXYOK_AUTH_OVERRIDE=true the Authorization header will be built using PROXY_AUTH_TYPE and PROXY_AUTH_TOKEN or PROXY_AUTH_TYPE, PROXY_AUTH_USERNAME and PROXY_AUTH_PASSWORD if properly provided.
  • See ./examples folder for more examples