Scripting

Plugin Walkthrough - 'hello-exchange' script.js

So to get started with the hello-exchange server script, first we are going to need to make the actual script that will be run:

  1. Create a new file called script.js, in the same directory as the config.json (plugins/src/plugins/hello-exchange/server/script.js)

  2. Fill this script.js with the code found in the box below.

hello-plugin script.js code
'use strict';

const { publicMeta, meta } = this.configValues;
const {
	app,
	loggerPlugin,
	toolsLib
} = this.pluginLibraries;
const helloWorld = require('hello-world-npm');
const moment = require('moment');

const init = async () => {
	loggerPlugin.info(
		'HELLO-PLUGIN PLUGIN initializing...'
	);

	if (!meta.private_message.value) {
		throw new Error('Configuration value private required');
	}
};

init()
	.then(() => {
		app.get('/plugins/hello-plugin/info', (req, res) => {
			loggerPlugin.verbose(
				req.uuid,
				'GET /plugins/hello-plugin/info'
			);

			return res.json({
				public_message: publicMeta.public_message.value,
				private_message: meta.private_message.value,
				library_message: helloWorld(),
				moment_timestamp: moment().toISOString(),
				exchange_info: toolsLib.getKitConfig().info
			});
		});
	})
	.catch((err) => {
		loggerPlugin.error(
			'HELLO-PLUGIN PLUGIN error during initialization',
			err.message
		);
	});

Check the screenshot below to compare and make sure you have the file in the correct location.

Calling the End Point

Now we have constructed 'hello-plugin', let's call the endpoint. First, we will need to build the plugin.

  1. If the terminals from earlier (when following how to set up dev mode) are no longer up, lets first get them going.

    1. In one terminal navigate to hollaex-kit/server and run docker-compose up

    2. In the other, enter the docker container with: docker exec -it server_hollaex-kit-server_1 /bin/bash

  2. With both the containers running build the plugin by running: node plugins/dev.js --plugin=hello-plugin inside the container (terminal we ran 'docker exec...' in)

Great news! This is all we had to do, and can now have a look at the plugin in the browser through the following URL:

http://localhost:10013/plugins/hello-plugin/info

You should see an output similar to below:

Last updated