0.2.3 • Published 3 years ago

cactuspi-service v0.2.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Cactus Pi Service

A backend service to be consumed by CactusPI Server and CactusPI Serverless.

Services

  • Publisher
    • AWS SQS
    • PubNub
    • MQTT (Home Assistant)

Plugins

Set up plugin configs

Create your own plugins

Instructions

You can import this library for your own service.

  1. npm install cactuspi-service

  2. Create config.json in your server project. You need to set up the configurations needed for each plugin and the publish service. Read more about the config set up for the plugins.

  3. Import the library in your service.

// import the library
const { Publisher, Plugins } = require('cactuspi-service');

// Create the publisher instance
const publisher = new Publisher(config);

// Create the plugins
pluginServices.forEach(({ name, service, options }) => {
  const plugin = new service(options);
  if (plugin.init) {
    plugin.init();
  }

  // register the end poins for each plugin
  app.get(`/${name}/:param?`, (req, res) => {
    plugin.fetch(
      (message, metadata) => {
        publisher.publish(message, metadata);

        res.status(200);
        res.send({ message, metadata });
      },
      (error) => {
        res.status(500);
        res.send({
          name: `Plugin Error: ${name}`,
          error,
        });
      }
    );
  });
});
0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago