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

rapidproxy

v1.0.4

Published

A smart and easy to use Ajax proxy for Javascript applications.

Downloads

3

Readme

rapidproxy

A smart and easy to use Ajax proxy for Javascript applications.

Background

Applications that run in a web browser may experience some restrictions when accessing remote servers. For instence:

  • CORS issues
  • Access a http server from a https application

A simple solution to these issues is to send the request through a proxy.

Web browser ==> Proxy Server ==> Target Server

The "Proxy Server" can be implemented in the programing language of your choice. For instance: PHP, NodeJS or Java. A Java implementation is available as a Maven library that you can easily add in to your projects, more info at this link: https://github.com/felipecarrillo100/rapidproxyserver

How to install:

npm install RapidProxy

How to include

import RapidProxy from "rapidproxy";

To use

Configure it first

Set the location of the proxy in your server:

RapidProxy.setProxyURL("location_of_your_proxy_server");  

Generate proxy (generate urls and headers to use in AJAX calls):

Use the "RapidProxy.generate" method to create the proxyfyed urls and headers.

  • urls: Is an object containing a list of urls that require proxy urls: {[key: string]: string}
  • requestHeaders: The list of headers to append to the AJAX call. Do not add Authentication, this is generated automatically.
  • useProxy: boolean value, if false no proxy is used, urls are called directly; if true proxy is used
const inputOptions: RapidProxyGenerateOptions = {
    useProxy: true,
    urls: {
        // Add more urls if needed the key can have any name, in this case link1, you will use the key to invocque the proxyfyed link
        link1: "https://jsonplaceholder.typicode.com/todos/1",
        link2: "https://some.other.server/address",
    },
    requestHeaders: {
        // Add any headers you want to pass
        Accept: "application/json"
    }
};

const proxy = RapidProxy.generate(inputOptions);
// proxy will contains a list of proxyfied links and headers
// proxy.urls  list of links to use in the AJAX requests.
// proxy.headersa list of headers to pass on each ajax request

You are done! Now you can perform AJAX calls through your PROXY server!

Making an AJAX request

This example shows the use with "fetch", but you can use any AJAX library as long as it supports passing headers

// We use the link1 that in this example correspondes to "https://jsonplaceholder.typicode.com/todos/1"
return fetch(proxy.urls.link1, {
    headers: proxy.headers
})
    .then((response: any) => {
        if (response.status === 200) {
            response.json().then((json:any) => {
                console.log(json)
            });
        }
    })

More complex examples with authentication

With basic authentication

For Basic Authentication username and password are encoded to a base64 hash, Authentication: Basic

const inputOptions: RapidProxyGenerateOptions = {
    useProxy: true,
    urls: {
        // Add more urls if needed, the keys can have any name, in this case link1, you will use the key to invocque the proxyfyed link
        link1: "https://jsonplaceholder.typicode.com/todos/1",
        link2: "https://some.other.server/address",
    },
    requestHeaders: {
        // Add all headers you want to pass, except for Authentication that is automatically generated
        Accept: "application/json"
    },
    authentication: {
        type: "Basic",
        username: "admin",
        password: "admin"
    }
};

const proxy = RapidProxy.generate(inputOptions);

With bearer authentication

Authentication is passed with a bearer, for instance a jwt token: Authentication: Bearer

const inputOptions: RapidProxyGenerateOptions = {
    useProxy: true,
    urls: {
        link1: "https://jsonplaceholder.typicode.com/todos/1",
        link2: "https://some.other.server/address",
    },
    requestHeaders: {
        Accept: "application/json"
    },
    authentication: {
        type: "Bearer",
        token: "sometokenvalu"
    }
};

const proxy = RapidProxy.generate(inputOptions);

With vault authentication.

No credentials will be passed, we assumed the server already has the credentials stored in a vault

const inputOptions: RapidProxyGenerateOptions = {
    useProxy: true,
    urls: {
        link1: "https://jsonplaceholder.typicode.com/todos/1",
        link2: "https://some.other.server/address",
    },
    requestHeaders: {
        Accept: "application/json"
    },
    authentication: {
        type: "Vault"
    }
};

const proxy = RapidProxy.generate(inputOptions);

Using a key to secure your proxy server

Optionally, you can set a secret key at your proxy server. Your client needs to know and pass the same key, if the key in the client does not match with the key in the server the request will be rejected.

// Set your key before generating any proxys, key must match with what the key have set in your server
RapidProxy.setProxySecuredKey("MySecretKey");

// Once the secured key has been set, you can generate proxies as usual
const proxy = RapidProxy.generate(inputOptions);