How to use the jayson.server function in jayson

To help you get started, we’ve selected a few jayson examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vitelabs / vite.js / test / RPC / bin / startRPC.js View on Github external
const jayson = require('jayson');

// create a server
const server = jayson.server({
    jsonrpcSuccess: function (args, callback) {
        callback(null, args[0] + args[1]);
    },
    jsonrpcError: function (args, callback) {
        callback({ code: 0, message: JSON.stringify(args) });
    },
    jsonrpcTimeoutSuccess: function (args, callback) {
        setTimeout(() => {
            callback(null, args[0] + args[1]);
        }, 100);
    },
    jsonrpcTimeoutError: function (args, callback) {
        setTimeout(() => {
            callback(null, args[0] + args[1]);
        }, 1000);
    }
github harpagon210 / steemsmartcontracts / plugins / JsonRPCServer.js View on Github external
function init(conf) {
  const {
    rpcNodePort,
  } = conf;

  serverRPC = express();
  serverRPC.use(cors({ methods: ['POST'] }));
  serverRPC.use(bodyParser.urlencoded({ extended: true }));
  serverRPC.use(bodyParser.json());
  serverRPC.set('trust proxy', true);
  serverRPC.set('trust proxy', 'loopback');
  serverRPC.post('/blockchain', jayson.server(blockchainRPC()).middleware());
  serverRPC.post('/contracts', jayson.server(contractsRPC()).middleware());

  http.createServer(serverRPC)
    .listen(rpcNodePort, () => {
      console.log(`RPC Node now listening on port ${rpcNodePort}`); // eslint-disable-line
    });
}
github harpagon210 / steemsmartcontracts / plugins / JsonRPCServer.js View on Github external
function init(conf) {
  const {
    rpcNodePort,
  } = conf;

  serverRPC = express();
  serverRPC.use(cors({ methods: ['POST'] }));
  serverRPC.use(bodyParser.urlencoded({ extended: true }));
  serverRPC.use(bodyParser.json());
  serverRPC.set('trust proxy', true);
  serverRPC.set('trust proxy', 'loopback');
  serverRPC.post('/blockchain', jayson.server(blockchainRPC()).middleware());
  serverRPC.post('/contracts', jayson.server(contractsRPC()).middleware());

  http.createServer(serverRPC)
    .listen(rpcNodePort, () => {
      console.log(`RPC Node now listening on port ${rpcNodePort}`); // eslint-disable-line
    });
}
github tiagovtristao / clipmir-desktop / src / server.js View on Github external
receivedConnections[uuid] = {};
  }

  return true;
}

function handleSetClipboardValueRequest({ uuid, value }) {
  console.log(Date.now(), `${processUUID} has new value '${value}' from ${uuid}`);

  clipboard.writeText(value);
  previousClipboardValue = value; // This avoids the just-received value from being sent out

  return true;
}

let jsonRpcServer = jayson.server({
  getName(args, callback) {
    callback(null, handleGetNameRequest());
  },
  connect(args, callback) {
    if (!objectHas(args, ['uuid'])) {
      callback(() => ({
        error: 'Invalid request',
      }));
    }
    else {
      callback(null, handleConnectRequest(args));
    }
  },
  setClipboardValue(args, callback) {
    if (!objectHas(args, ['uuid', 'value'])) {
      callback(() => ({
github yuchiu / Netflix-Clone / user-service / src / index.js View on Github external
import jayson from "jayson";

import models from "./models";
import RPCInterfaces from "./RPCInterfaces";
import { SERVICE_USER_PORT, NODE_ENV } from "./config/secrets";

// create a server
const server = jayson.server(RPCInterfaces);

models.sequelize.sync().then(() => {
  server
    .http()
    .listen(SERVICE_USER_PORT, () =>
      console.log(
        `  User Service listenning on port ${SERVICE_USER_PORT} in "${NODE_ENV}" mode`
      )
    );
});
github yuchiu / Netflix-Clone / movie-service / src / index.js View on Github external
import jayson from "jayson";
import { SERVICE_MOVIE_PORT, NODE_ENV } from "./config/secrets";
import ESClient from "./config/ESClient.config";
import RPCInterface from "./RPCInterfaces";

// create a server
const server = jayson.server(RPCInterface);

ESClient.ping({ requestTimeout: 30000 }, error => {
  if (error) {
    console.error(`Elasticsearch connection failed: ${error}`);
  } else {
    console.log("Elasticsearch connection success");
  }
});

server
  .http()
  .listen(SERVICE_MOVIE_PORT, () =>
    console.log(
      `  Movie Service listenning on port ${SERVICE_MOVIE_PORT} in "${NODE_ENV}" mode`
    )
  );
github 0xbitcoin / tokenpool / lib / peer-interface.js View on Github external
async initJSONRPCServer()
     {

       var self = this;

       console.log('listening on JSONRPC server localhost:8080')
         // create a server
         var server = jayson.server({
           ping: function(args, callback) {

               callback(null, 'pong');

           },

           getPoolProtocolVersion: function(args, callback) {

                return "1.02";

           },

           getPoolEthAddress: function(args, callback) {

               callback(null, self.getMintHelperAddress().toString() );
github leapdao / leap-node / src / api / jsonrpc.js View on Github external
module.exports = async (bridgeState, tendermintPort, db, app) => {
  const withParams = method => {
    return params => method(...params);
  };

  const { nodeApi, methodsWithCallback } = getMethods(
    bridgeState,
    db,
    app,
    tendermintPort
  );

  api.use(jayson.server(methodsWithCallback).middleware());

  return {
    listenHttp: async ({ host, port }) => {
      return new Promise(resolve => {
        const server = api.listen(port || 8645, host || 'localhost', () => {
          resolve(server.address());
        });
      });
    },
    listenWs: ({ host, port }) => {
      const wsServer = new WsJsonRpcServer({
        port: port || 8646,
        host: host || 'localhost',
      });

      // register an RPC method
github ethereumjs / ethereumjs-client / test / rpc / helpers.js View on Github external
startRPC (methods, port = 3000) {
    const server = jayson.server(methods)
    const httpServer = server.http()
    httpServer.listen(port)
    return httpServer
  },