Markdown to html/pdf
This app exposes HTTP endpoints to convert markdown files to HTML or PDF after the client paid a lightning invoice.
How does it work?
- If no proof of payment is provided the rack lightning middleware creates a Lightning invoice and returns a
402 Payment RequiredHTTP status code with a
application/vnd.lightning.bolt11content type header and a Lightning invoice as a body.
- The client pays the invoice and does a second request providing the proof of payment / the preimage of the Lightning
payment in a
- Now the lightning middleware checks the if the invoice was paid and proceeds to the sinatra app doing the convertion.
Have a look at the server code:
- config.ru - where the magic happens: loading the lightning middleware
- converter.rb - the actual sinatra app (no lightning related code in here; all handled by the middleware)
Usage details about the rack lightning middleware can be found here
Server and client are using connecting (gRPC) to the Lightning Network Daemon(lnd) to create and pay invoices.. A running node with funded channels is required. Details about lnd can be found on their github page
The following endpoints are available:
converts markdown in the request body to PDF and returns the PDF file content
converts the markdown in the request body to HTML and returns the html file content
requirements: you need a running lnd node with funded, open channels. Check the lnd github page for information about lnd.
$ ruby client.rb [path to markdown file] [format] $ $ # example: $ ruby client.rb ./README.md html
What is the Lightning Network?
The Lightning Network allows to send real near-instant microtransactions with extremely low fees. It is a second layer on top of the Bitcoin network (and other crypto currencies). Thanks to this properties it can be easily used for automated machine to machine payments.
The gem is available as open source under the terms of the MIT License.