Skip to content

dannielum/cactuspi-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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,
        });
      }
    );
  });
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published