prxy

2.0.3 • Public • Published

prxy

Client/Server wrapper for simple modules with top level functions that return promises or streams.

API

serve(modules, options)

Start an http server proxy for the given module.

  • modules - the module to proxy. The top level async functions (that return promises or streams) will be proxied. To proxy multiple modules, pass an array of objects with key api specifying the module and ns specifying the namespace (omit to use default namespace).
  • options - server options
    • port - port to listen on

load(options)

Configure how to communicate with a remote service.

  • options - client options
    • url - The url to access the remote serivce (e.g. http://remotehost:1234)
    • ns - The namespace associated with the service (omit to use default)
    • local - Alternative to load a local module directly (absolute file path or module from package.json)

Usage

Server

const Prxy = require('prxy');
 
const math = {
   add: async (a, b) => {
 
       return a + b;
   }
}
 
Prxy.serve(math, { port: 3000 });

Client

const Prxy = require('prxy');
const MathService = Prxy.load({ url: 'http://localhost:3000' });
const result = await MathService.add(1, 1);
console.log('1 + 1 =', result);

Readme

Keywords

Package Sidebar

Install

npm i prxy

Weekly Downloads

0

Version

2.0.3

License

ISC

Unpacked Size

70.3 kB

Total Files

7

Last publish

Collaborators

  • dsixe
  • scpatel