This repo is an example of how to build a QuickNode Marketplace add-on using Go and PostgreSQL
It implements the 4 provisioning routes that a partner needs to integrate with Marketplace, as well as the required Healthcheck route.
It also has support for:
- RPC methods via a
POST /rpc
route - A dashboard view with Single Sign On using JSON Web Tokens (JWT).
To install and run the application locally:
- Clone this repo.
- Create a postgresql databse called
marketplace-starter-go
:
createdb marketplace-starter-go
- Copy the
.env.example
to.env
and update theDB_URL
to one that matches your local postgresql DB.
cp .env.example .env
- Run migrations:
go run migrate/migrate.go
- Build the code:
go build
- Start the web server by running the executable:
./marketplace-starter-go
The application has 4 provisioning routes protected by HTTP Basic Auth:
POST /provision
PUT /update
DELETE /deactivate_endpoint
DELETE /deprovision
It has a public healthcheck route that returns 200 if the service and the database is up and running:
GET /healthcheck
It has a dashboard that can be accessed using Single Sign On with JSON Web Token (JWT):
GET /dash/:id?jwt=foobar
It has an JSON RPC route:
POST /rpc
You can use the qn-marketplace-cli tool to quickly test your add-on while developing it.
For the commands below, the --basic-auth
flag is the Base64 encoding of username:password
.
You need to make sure to replace that with your valid credentials (as defined in your .env
file).
../qn-marketplace-cli/qn-marketplace-cli healthcheck --url http://localhost:3010/healthcheck
../qn-marketplace-cli/qn-marketplace-cli pudd --base-url http://localhost:3010 --basic-auth dXNlcm5hbWU6cGFzc3dvcmQ= --quicknode-id foobar
Below, make sure that the jwt-secret
matches QN_SSO_SECRET
in .env
file.
../qn-marketplace-cli/qn-marketplace-cli sso --url http://localhost:3010/provision --basic-auth dXNlcm5hbWU6cGFzc3dvcmQ= --jwt-secret jwt-secret --email [email protected] --name jon --org QuickNode --quicknode-id foobar
../qn-marketplace-cli/qn-marketplace-cli rpc --url http://localhost:3010/provision --rpc-url http://localhost:3010/rpc --rpc-method qn_test --rpc-params "[\"abc\"]" --basic-auth dXNlcm5hbWU6cGFzc3dvcmQ= --quicknode-id foobar
To obtain a basic auth string, you can use Go or your language of choice with your username and password, as such:
package main
import (
"encoding/base64"
"fmt"
)
func main() {
data := "username:password"
encodedData := base64.StdEncoding.EncodeToString([]byte(data))
fmt.Println(encodedData)
}
MIT