Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@unleash/proxy

Package Overview
Dependencies
Maintainers
2
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unleash/proxy

The Open-Soruce Unleash Proxy

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.6K
increased by64.2%
Maintainers
2
Weekly downloads
 
Created
Source

The Unleash Proxy

The Unleash Proxy simplifies integration with frontend & native applications running in the context of a specific user. The Unleash proxy sits between the proxy SDK and the Unleash API and ensures that you internal feature toggle configuration is not exposed to the world. It provide :

  • High performance - a single proxy instance can handle up towards +7000 req/s, and can be horizontally scaled.
  • Privacy for end-users - Your end users are not exposed to the unleash API and can be hosted by you This ensures no user data (userId, IPs, etc) is shared.
  • Secure - It is controlled by you, and can hosted on your domain. In addition no feature toggle configuration is shared with the user, only evaluated toggles.

You can read more about the proxy in our documentation

Run The Unleash Proxy

The Unleash proxy is a small stateless HTTP application you run. The only requirement is that it needs to be able to talk with the Unleash API (either Unleash OSS or Unleash Hosted).

Run with Docker

The easies way to run Unleash is via Docker. We have published a docker image on docker hub.

Step 1: Pull

docker pull docker pull unleashorg/unleash-proxy

Step 2: Start

docker run \
   -e UNLEASH_PROXY_SECRETS=some-secret \
   -e UNLEASH_URL='https://app.unleash-hosted.com/demo/api/' \
   -e UNLEASH_API_TOKEN=56907a2fa53c1d16101d509a10b78e36190b0f918d9f122d \
   -p 3000:3000 \
   unleashorg/unleash-proxy

You should see the following output:

Unleash-proxy is listening on port 3000!

Step 3: verify

In order to verify the proxy you can use curl and see that you get a few evaluated feature toggles back:

curl http://localhost:3000/proxy -H "Authorization: some-secret"  

Expected output would be something like:

{
	"toggles": [{
		"name": "demo",
		"enabled": true,
		"variant": {
			"name": "disabled",
			"enabled": false
		}
	}, {
		"name": "demoApp.step1",
		"enabled": true,
		"variant": {
			"name": "disabled",
			"enabled": false
		}
	}]
}

Health endpoint

The proxy will try to synchronize with the Unleash API at startup, until it has successfully done that the proxy will return HTTP 503 - Not Read? for all request. You can use the health endpoint to validate that the proxy is ready to recieve requests:

curl curl http://localhost:3000/proxy/health -I
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag
Content-Type: text/html; charset=utf-8
Content-Length: 2
ETag: W/"2-eoX0dku9ba8cNUXvu/DyeabcC+s"
Date: Fri, 04 Jun 2021 10:38:27 GMT
Connection: keep-alive
Keep-Alive: timeout=5

Available options

OptionEnvironment VariableDefault valueRequiredDescription
unleashUrlUNLEASH_URLn/ayesAPI Url to the Unleash instance to connect to
unleashApiTokenUNLEASH_API_TOKENn/ayesAPI token (client) needed to connect to Unleash API.
proxySecretsUNLEASH_PROXY_SECRETSn/ayesList of proxy secrets the proxy accept. Proxy SDKs needs to set the Proxy secret as the Authorization heder when querying the proxy
proxyBasePathPROXY_BASE_PATH"/proxy"noThe base path to run the proxy from. Defaults to "/proxy"
unleashAppNameUNLEASH_APP_NAME"unleash-proxy"noApp name to used when registering with Unleash
refreshIntervalUNLEASH_FETCH_INTERVAL5000noHow often the proxy should query Unleash for updates, defined in ms.
metricsIntervalUNLEASH_METRICS_INTERVAL30000noHow often the proxy should send usage metrics back to Unleash, defined in ms.
environmentUNLEASH_ENVIRONMENTundefinednoIf set this will be the environment used by the proxy in the Unleash Context. It will not be possible for proxy SDKs to override the environment if set.
projectNameUNLEASH_PROJECT_NAMEundefinednoThe projectName (id) to fetch feature toggles for. The proxy will only return know about feature toggles that belongs to the project, if specified.
loggern/aSimpleLoggernoRegister a custom logger.
logLevelLOG_LEVEL "warn"noUsed to set logLevel. Supported options: "debug", "info", "warn", "error" and "fatal

Run with Node.js:

STEP 1: Install dependency

 npm install @unleash/proxy

STEP 2: use in your code

const port = 3000;

const { createApp } = require('@unleash/proxy');


const app = createApp({
    unleashUrl: 'https://app.unleash-hosted.com/demo/api/',
    unleashApiToken: '56907a2fa53c1d16101d509a10b78e36190b0f918d9f122d',
    proxySecrets: ['proxy-secret', 'another-proxy-secret', 's1'],
    refreshInterval: 1000,
    // logLevel: 'info',
    // projectName: 'order-team',
    // environment: 'development',
});

app.listen(port, () =>
    // eslint-disable-next-line no-console
    console.log(`Unleash Proxy listening on http://localhost:${port}/proxy`),
);

Proxy clients

To make the integration simple we have developed proxy client SDKs. You can find them all in our documentation:

Keywords

FAQs

Package last updated on 04 Jun 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc