Giter VIP home page Giter VIP logo

cc-health-check-relay's Introduction

Community Chains Health Check Relay

Server to relay health check requests to RPC nodes within a closed network.

Build and run from source

Install dependencies

npm install

Run tests

npm test

Build

npm run build

Start relay server

npm start

Run via Docker

docker run -p 3100:3100/tcp decentralizedauthority/cc-health-check-relay:x.x.x

Usage

The server is designed to relay GET or POST requests.

GET request relay body

interface RelayServerGetRequest {
  method: 'GET'
  host: string
  path: string
  port: number
  protocol: string
  timeout: number
}

POST request relay body

interface RelayServerPostRequest {
  method: 'POST'
  host: string
  path: string
  port: number
  protocol: string
  timeout: number
  body: string
  type: string
}

Relay response

interface RelayServerError {
  statusCode?: number
  message: string
}
interface RelayServerResponse {
  error: null|RelayServerError
  result: any                    // response body from relayed RPC request
  responseTime: number           // time in ms to complete request
}

Example relay request using Superagent

import request from 'superagent';

const rpcRequestBody = {
  jsonrpc: '2.0',
  id: 1,
  method: 'eth_blockNumber',
  params: [],
};

const relayRequest = {
  host: '10.0.0.1',
  path: '/',
  port: 8545,
  method: 'POST',
  protocol: 'http',
  body: JSON.stringify(rpcRequestBody),
  type: 'application/json',
  timeout: 10000,
};

request
  .post('http://localhost:3100/relay')
  .type('application/json')
  .send(relayRequest)
  .timeout(10000)
  .then((res) => {
    const { error, result, responseTime } = res.body;
    console.log(`Request completed in ${responseTime}ms`);
    if(error) { // handle relay error
      const { statusCode, message } = error;
      console.error(`Error: "${message}" Status Code: ${statusCode || 'none'}`);
    } else { // handle relay result
      console.log(result);
    }
  })
  .catch((err) => {
    // handle error
  });

License

Apache License Version 2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.