1.9.2 • Published 2 years ago

askbitcoin v1.9.2

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

"Ask Bitcoin Banner Logo"

Typescript API Server

Installation

To download and install dependencies run npm install

Running

To run the API server run npm start

Testing

To run tests run npm run test

Development

To commit new code run npm run commit

Configuration

Rabbi may be configured in several ways depending on the needs of your environment.

1) Environment Variables

2) Configuration Files

3) Command Line Arguments

The same variables are used in all three options, however in configuration files and command line arguments all variables are strictly lower case, whereas in environment variables they may be upper case or lower case.

Environment Variables

VariableDescriptionDefaultRequired
HTTP_API_ENABLEDServe JSON API.truefalse
AMQP_ENABLEDCommunicate between components via RabbitMQ. Require by some features under src/actors/truefalse
POSTGRES_ENABLEDWill automatically begin logging events to postgrestruetrue
DATABASE_URLPostgres connection Url in the form `postgres://user:password@host:port/database | | true
HTTP_API_HOSTIP address to bind when serving. Set to 127.0.0.1 or localhost for local-only access0.0.0.0false
HTTP_API_PORTPort to bind when accepting new API client connections.5200false
PROMETHEUS_ENABLEDExpose /metrics endpoint to allow prometheus to scrape default and your custom metrics.truefalse
LOKI_ENABLEDStream logs from the application to a loki log aggregation server.falsefalse

Configuration Files

The app loads files from a hierarchy each overriding the previous. First the system level config files are loaded, then user level config file, finally the local config file for development purposes

1) /etc/rabbi/rabbi.json

2) ~/.rabbi/rabbi.json

3) .config/rabbi.json

Config files are JSON objects containing key value pairs where the key is the config variable and the value is the value of the variable. Numbers and booleans will be parsed and made available. Variable names can be either upper or lower case.

{
	"database_url": "postgres://postgres:12321423fekrefk@mydb.example.com:5432/boostpow",
	"http_api_port": 3000,
	"loki_enabled": true,
	"loki_url": "https://loki.example.com",
	"prometheus_enabled": false
}

System Events

When using AMQP you may bind the following events as routingkeys to receive delivery of these messages to your application. You may also choose to receive these events via Webhook by configuring the WEBHOOK_URL and WEBHOOKS_ENABLED variables.

EventDescription
prometheus.metrics.scrapedEvery time prometheus scrapes
http.requestWhen a client makes a request to the HTTP API

Additional events can be published and listened to using rabbi

import { events } from 'rabbi'

events.publish('game.ended', { winner: 'nobody' })

Then in another component or process, or app connected to the same AMQP:

import { events } from 'rabbi'

events.on('game.ended', (message: Buffer, json?: any) => {

  console.log('---- GAME OVER ----')

  if (json && json.winner === 'nobody') {

    console.log('nobody wins')

  }

})