Web services and website files for https://lightning.ws.
lightning.ws hosts paywalled web services / APIs that are payable via the Lightning Network.
It's "eating your own dogfood" for the project ln-paywall. For more information please visit the project's GitHub repository: https://github.com/philippgille/ln-paywall
The Docker image for deploying the web service is on Docker Hub: https://hub.docker.com/r/philippgille/ln-ws-api
- A running lnd node, either on a remote host and accessible from outside, or on the same host, in which case you can either start this container in "host network" mode, or use the container's gateway IP address to reach the host's localhost
- An Azure Cognitive Services "Translator Text API" subscription key
- An Azure Cognitive Services "Computer Vision" subscription key
The following steps are for running the website and web service locally:
- Create a data directory on the host:
mkdir api/data
- Copy the
tls.cert
andinvoice.macaroon
from your lnd to theapi/data
directory - Change the values in the
.env
file, which contains the lnd address and Azure region and API keys - Start the website and web service via Docker Compose:
docker-compose up -d
Now you can either use the interactive client on the website or make the requests programmatically:
- Website:
- If you did the above: https://localhost:2015, otherwise check out the deployed version on https://lightning.ws
- Programmatically:
- Send a request to generate an invoice:
- QR code:
curl -k https://localhost:2015/api/qr
- Translation:
curl -k https://localhost:2015/api/translate
- OCR (text recognition):
curl -k https://localhost:2015/api/ocr
- QR code:
- Take the invoice from the response body and pay it via the Lightning Network
- Send the request again, this time with the preimage as payment proof (hex encoded) and the data as query parameter:
- QR code:
curl -k -H "x-preimage: 123abc456def" https://localhost:2015/api/qr?data=testtext
- Translation:
curl -k -H "x-preimage: 123abc456def" https://localhost:2015/api/translate?text=Hallo%Welt&to=en
- OCR:
curl -k -H "x-preimage: 123abc456def" https://localhost:2015/api/ocr?imageUrl=http%3A%2F%2Fexample%2Ecom%2Fimage%2Epng
- QR code:
- Send a request to generate an invoice:
Note: The deployment on https://lightning.ws uses a separate subdomain for the API, which is why there's no
/api/
in the path. If want to deploy this in a similar way you can just change the reverse proxy configuration in theCaddyfile
.
The configuration files in this repository only serve for a quick start for testing purposes!
The deployment on https://lightning.ws uses a different, non-public configuration.
In production, you should:
- Use Redis as storage for ln-paywall to make horizontal scaling of the web service containers possible (you can use the implementation in the
storage
package of ln-paywall, see here)- With persistence for backups and a proper cluster for redundancy
- Use Docker Swarm or Kubernetes for container orchestration to make it easy to run the containers on a cluster of host machines
- Set up auto-scaling for the web service containers
- Add rate limiting and other DoS protection measures
- Add proper logging (for example using the Elastic Stack, Graylog or a custom combination like Fluent Bit + Elasticsearch + Kibana (see this article))
- Add proper metric collection (for example with Prometheus + Grafana)
- Maybe use traefik instead of Caddy as reverse proxy
- Maybe use nginx for serving the website files
- ...