0.14.1 • Published 5 days ago

@ethersphere/gateway-proxy v0.14.1

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
5 days ago

gateway-proxy

Tests Dependency Status FOSSA Status npm.io standard-readme compliant js-standard-style npm.io npm.io

Proxy to you bee node which aims to work as a public or personal gateway or to be used in CI for uploading to Swarm.

Warning: This project is in beta state. There might (and most probably will) be changes in the future to its API and working. Also, no guarantees can be made about its stability, efficiency, and security at this stage.

This project is intended to be used with Bee version 1.7.0-bbf13011. Using it with older or newer Bee versions is not recommended and may not work. Stay up to date by joining the official Discord and by keeping an eye on the releases tab.

Table of Contents

Install

git clone https://github.com/ethersphere/gateway-proxy.git
cd gateway-proxy

Usage

The proxy can manage postage stamps for you in 4 modes of operation:

  1. It can just proxy requests without manipulating the request
  2. It can add/replace the request postage stamp with one provided through environment variable POSTAGE_STAMP
  3. It can add/replace the request postage stamp with an auto-bought stamp or existing stamp that fulfils the amount, depth and is not too full or about to expire. To enable this, provide at minimum POSTAGE_DEPTH, POSTAGE_AMOUNT and BEE_DEBUG_API_URL.
  4. It can extend the TTL of a stamp that is about to expire. To enable this, set POSTAGE_EXTENDSTTL=true, provide POSTAGE_AMOUNT, POSTAGE_DEPTH with the desired amount to use and POSTAGE_TTL_MIN above with a number above or equal to 60.

In modes 1, 2 and 3, the proxy can be configured to require authentication secret to forward the requests. Use the AUTH_SECRET environment variable to enable it.

Bzz.link support

Gateway proxy has support for Bzz.link which allows translating Swarm CIDs and ENS names placed under subdomains into /bzz call. This allows to have better security model for your web applications.

In order to use Bzz.link, set the HOSTNAME environment variable, and either or both of CID_SUBDOMAINS and ENS_SUBDOMAINS according to your requirements. You may also need to set up DNS with wildcard subdomain support.

Reupload pinned content

It can reupload existing pinned content that appear as not retrievable. To enable this, provide REAUPLOAD_PERIOD with the miliseconds that represent the time to periodicaly check pinned content status.

Examples

1. No postage stamp

npm run start

2. Hardcoded postage stamp

export POSTAGE_STAMP=f1e4ff753ea1cb923269ed0cda909d13a10d624719edf261e196584e9e764e50

npm run start

3. Autobuy postage stamps

export POSTAGE_DEPTH=20
export POSTAGE_AMOUNT=1000000
export POSTAGE_TTL_MIN=60

npm run start

4. Extends stamps TTL

export POSTAGE_EXTENDSTTL=true
export POSTAGE_TTL_MIN=60
export POSTAGE_DEPTH=20
export POSTAGE_AMOUNT=1000000

npm run start

Reupload pinned content

export REUPLOAD_PERIOD=30000

npm run start

Enable authentication

export AUTH_SECRET="this_is_some_secret_string"

npm run start

Environment variables

NameDefault ValueDescription
BEE_API_URLhttp://localhost:1633URL of the Bee node API
BEE_DEBUG_API_URLhttp://localhost:1635URL of the Bee node Debug API. Required for postage stamps autobuy and hashed identity header.
AUTH_SECRETundefinedAuthentication secret, disabled if not set (this secret is checked in the request header authorization).
HOSTNAMElocalhostHostname of the proxy. Required for Bzz.link support.
PORT3000Port of the proxy.
POSTAGE_STAMPundefinedPostage stamp that should be used for all upload requests. If provided, the autobuy feature is disabled.
POSTAGE_DEPTHundefinedPostage stamp depth to be used when buying new stamps or selecting existing stamps.
POSTAGE_AMOUNTundefinedPostage stamp amount to be used when buying new stamps or selecting existing stamps.
POSTAGE_USAGE_THRESHOLD0.7Usage percentage at which new postage stamp will be bought (value between 0 and 1).
POSTAGE_USAGE_MAX0.9Usage percentage at which existing postage stamp should not be considered viable ( values 0 to 1).
POSTAGE_TTL_MINautobuy: 5 * POSTAGE_REFRESH_PERIOD. extends TTL: undefinedIn autobuy, Minimal time to live for the postage stamps to still be considered for upload (in seconds). In extends TTL is mandatory and required to be above 60 seconds
POSTAGE_REFRESH_PERIOD60How frequently are the postage stamps checked in seconds.
CID_SUBDOMAINSfalseEnables Bzz.link subdomain translation functionality for CIDs.
ENS_SUBDOMAINSfalseEnables Bzz.link subdomain translation functionality for ENS.
REMOVE_PIN_HEADERtrueRemoves swarm-pin header on all proxy requests.
LOG_LEVELinfoLog level that is outputted (values: critical, error, warn, info, verbose, debug)
POSTAGE_EXTENDSTTLfalseEnables extends TTL feature. Works along with POSTAGE_AMOUNT
EXPOSE_HASHED_IDENTITYfalseExposes x-bee-node header, which is the hashed identity of the Bee node for identification purposes
REUPLOAD_PERIODundefinedHow frequently are the pinned content checked to be reuploaded.
HOMEPAGEundefinedSwarm hash that loads as the homepage of gateway-proxy
REMAPundefinedSemicolon separated name=hash values to rewrite Swarm hashes to human-friendly names
ALLOWLISTundefinedComma separated list of hashes, ENS domains or CIDs to allow
ALLOW_USER_AGENTSundefinedComma separated list of user-agent substrings to give unlimited access to

Curl

Upload a file

curl \
  -X POST http://localhost:3000/bzz \
  -H "Accept: application/json, text/plain, */*" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "swarm-postage-batch-id: f1e4ff753ea1cb923269ed0cda909d13a10d624719edf261e196584e9e764e50" \
  -H "authorization: this_is_some_secret_string"
{"reference":"a30e9c3ecbe68450924b20a7d46f745fa04289f7381826bdd51289aee4ad32f6"}

Download

curl \
  -L http://localhost:3000/bzz/a30e9c3ecbe68450924b20a7d46f745fa04289f7381826bdd51289aee4ad32f6 \
  -H "authorization: this_is_some_secret_string" \
  --output -

API

EndpointResponse codeResponse text
GET /health200OK
403Forbidden
GET /readiness200OK
403Forbidden
502Bad Gateway when can not connect to Bee node
GET /bzz/:swarmhash200, 403, ...See official bee documentation
POST /bzz201, 403, ...See official bee documentation
GET /bytes/:swarmhash200, 403, ...See official bee documentation
POST /bytes201, 403, ...See official bee documentation
GET /chunks/:swarmhash200, 403, ...See official bee documentation
POST /chunks201, 403, ...See official bee documentation
POST /soc/:owner/:id201, 403, ...See official bee documentation
GET /feeds/:owner/:topic200, 403, ...See official bee documentation
POST /feeds/:owner/:topic201, 403, ...See official bee documentation

Contribute

There are some ways you can make this module better:

  • Consult our open issues and take on one of them
  • Help our tests reach 100% coverage!
  • Join us in our Discord chat in the #develop-on-swarm channel if you have questions or want to give feedback

Local development with Bzz.link

Local development with the subdomain Bzz.link support is a bit more tricky as it requires to have a way how to direct local subdomains to given URL.

Easy way is to have one testing CID that you will put directly to /etc/hosts and use only that for testing.

bah5acgzamh5fl7emnrazttpy7sag6utq5myidv3venspn6l5sevr4lko2n3q.localhost 127.0.0.1

If you want fully functional setup than you have to locally install some DNS client that will provide you this functionality. See for example here for dnsmasq solution.

Maintainers

License

BSD-3-Clause

FOSSA Status

0.14.1

5 days ago

0.14.0

11 days ago

0.13.0

2 months ago

0.12.0

4 months ago

0.11.0

4 months ago

0.10.0

5 months ago

0.9.3

6 months ago

0.9.0

6 months ago

0.8.0

6 months ago

0.9.2

6 months ago

0.9.1

6 months ago

0.7.0

9 months ago

0.6.0

2 years ago

0.5.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.1.0

2 years ago