npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-rpc-lite

v2.0.8

Published

json-rpc-lite

Downloads

20

Readme

json-rpc-lite

very simple jsonrpc base on express

NPM version npm download David deps

Install

npm i json-rpc-lite -S

Usage

server

加载处理模块

const JSONRPC = require('json-rpc-lite');

JSONRPC.loadRouter(path.join(__dirname, 'rpc/')); // 自动加载目录中 xxx_rpc.js文件 xxx为模块名 文件中 函数名为yyyRpc,其中yyy为导出的模块方法,非此格式函数 无法rpc调用

example:connector_rpc.js

var service = module.exports = {
    init: function () {
        logger.debug('[connector_prc]init');
    },
    kickRpc: function (input, cb) {
        logger.debug('[rpc]kick:%j', input);
        let checkParam = validate(input, jsonSchemaData.kick_rpc);
        if (!checkParam.valid) {
            let errMsg = checkParam.errors[0].message;
            cb(new Error(errMsg));
            return;
        }
        cb(null, {});        
        return;
    }
}

input: argument cb: callback(error, returnValue)

route

baseon express

var inputSchema = {
    "type": "object",
    "properties": {
        "id": {
            "type": "string"
        },
        "module": {
            "type": "string"
        },
        "method": {
            "type": "string"
        },
        "args": {
            "type": "object",
        }
    },
    "required": ["id", "module", "method", "args"]
};
var service = module.exports = {
    invokeAction: {
        method: ['POST'],
        handler: function (req, res) {
            logger.debug('[rpc]invoke:%j', req.body);
            var checkParam = validate(req.body, inputSchema);
            if (!checkParam.valid) {
                let errMsg = checkParam.errors[0].message;
                logger.error('[rpc]invoke param error:%s', errMsg);
                res.json(commonUtil.json(-1, errMsg));
                return;
            }
            try {
                JSONRPC.handlePOST(req, res);
            } catch (error) {
                logger.error('[rpc]call fatal:', error);
                res.json({
                    status: -1,
                    msg: 'fatal error'
                });
            }
            return;
        }
    }
};

client

jsonrpcClientPool.invokeWithHost('http://127.0.0.1:8011/api/rpc/invoke', 'connector', 'kick', {
                echo: 'hello'
            }).then(function(resp) {
                logger.debug('logid:%s [rpc]kick remote success:%j', logid, resp);
                return Promise.resolve();
            }).catch(function(error) {
                logger.error('logid:%s [rpc]kick remote failed:', logid, error.stack);
                return Promise.resolve();
            });

增加debug_server 只能目标地址 以渠道invokeWithHost

JsonRpc.invokeWithRalV2('dlpProxyRpcMock', {
                debug_server: {
                    'host': host.ip,
                    port: host.port
                }
            },
            'connector',
            'ping',
            postBody,
            this.tracer.logid
        )

See example.

License

The MIT License