1.0.1 • Published 5 years ago

rach-server v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Rach Server

Install from NPM

npm install rach-server

Usage

Sample code. Run using node app.js

// app.js

const RachServer = require('rach-server');

// Modify internal actions used by Rach
const actions = {
    'authTest': function (cred) {
        return cred["username"] === "su" && cred["password"] === "pass";
    },
};

// Analogous to Remote Procedure Calls
const services = {
    '/version':
        function (rach, client, on_err, on_result) {
            on_result('1.0');
        },
    '/client.public_id':
        function (rach, client, on_err, on_result) {
            on_result(client.public_id);
        },
    '/remainder':
        function (rach, client, on_err, on_result, x, y) {
            try {
                on_result(x % y);
            } catch (e) {
                on_err(e.message || 'Generic service error');
            }
        },
};

const rachServer = new RachServer(actions, services, console, 8080);

// Add a local subscription
rachServer.addSub('/one/two', function (data) {
    console.info(data);
}, []);

rachServer.start();
1.0.1

5 years ago

1.0.0

5 years ago