Socket
Socket
Sign inDemoInstall

@technik-sde/foxy

Package Overview
Dependencies
0
Maintainers
43
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @technik-sde/foxy

> Customizable frontend-proxy, supporting multiple handlers for input-urls


Version published
Weekly downloads
12
Maintainers
43
Created
Weekly downloads
 

Readme

Source

simple frontend proxy

Customizable frontend-proxy, supporting multiple handlers for input-urls

Usage

import { Foxy, utils } from "foxy";

const proxy = new Foxy({
  handlers: [
    {
      use({ url }) {
        return myUrlFormat.test(url);
      },
      getImageURL({ url }) {
        return Promise.resolve(buildMyUrlScheme(url));
      },
      getImageInfo({ url }) {
        return utils.loadImage(buildMyUrlScheme(url))
      }
    }
  ]
});

const finalUrl = await proxy.getImageURL({ url: 1234 });
const imageMetadata = await proxy.getImageInfo({ url: 1234 });

Multiple handlers are supported and are resolved from first to last index. The first handler returning true on use, will be selected, if the given method-name is defined:

import { Foxy } from "foxy";

const proxy = new Foxy({
  handlers: [
    {
      use({ url }) {
        return myUrlFormat.test(url);
      },
      getImageURL({ url }) {
        return Promise.resolve(buildMyUrlScheme(url));
      }
    },
    {
      use: () => true,
      // overwrites default exception to always return false
      getImageURL({ url }) { return Promise.resolve(false); } 
    }
  ]
});

const finalUrl = await proxy.getImageURL({ url: "abc" }); // false, when not myUrlFormat

Per default the following methods are supported via api: getImageURL, getImageInfo, getVideoURL, getVideoInfo. The generic method get(methodName: string, requestData: AnyObject) may be used to access any custom methods defined on handlers. e.g.

import { Foxy } from "foxy";

const proxy = new Foxy({
  handlers: [
    {
      use({ url }) {
        return myUrlFormat.test(url);
      },
      getJSON({ url }) {
        return fetch(buildMyUrlScheme(url)).then(response => response.json());
      }
    }
  ]
});

const json = await proxy.get("getJSON", { url: "my-json-url" });

FAQs

Last updated on 04 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc