A backend service to be consumed by CactusPI Server and CactusPI Serverless.
- Publisher
- AWS SQS
- PubNub
- MQTT (Home Assistant)
You can import this library for your own service.
-
npm install cactuspi-service
-
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.
-
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,
});
}
);
});
});