Plugins are javascript files or npm packages that get required in the Irisfile. All plugins extend some base class.
You must implement get path(), listen() and stop(). send() is optional.
Take a look at the base class for a list of the available methods and events, like this.process().
'use strict';
const Dock = require('../../lib/bases/Dock');
const http = require('http');
const requestIp = require('request-ip');
class HTTPDock extends Dock {
    constructor(name, protocol) {
        super(name, protocol);
        this._server = null;
        this._listening = false;
    }
    get path() {
        return __filename;
    }
    listen() {
        this._server = http.createServer(this._handleRequest.bind(this));
        if (!this._listening) {
            this._server.listen(this.config.port, () => {
                this._listening = true;
                this.logger.info(`[HTTP Dock] Listening on port ${this.config.port}...`);
            });
        }
    }
    stop() {
        if (this._listening) {
            this._server.close();
            this._listening = false;
            this.logger.info('[HTTP Dock] Stopped listening');
        }
    }
    _handleRequest(request, response) {
        const chunks = [];
        const meta = {
            ip: requestIp.getClientIp(request)
        };
        request.socket.setNoDelay();
        request.on('data', function (chunk) {
            chunks.push(chunk);
        });
        request.on('end', function () {
            const data = Buffer.concat(chunks);
            this.process(data, meta, (message) => {
                response.statusCode = 200;
                if (message) {
                    response.write(message);
                    this.logger.verbose('[HTTP Dock] Sent response to client');
                }
                response.end();
            });
        }.bind(this));
    }
}
module.exports = new HTTPDock('http', 'HTTP');
You must implement get path() and handle().
Take a look at the base class for a list of the available methods and events.
'use strict';
const Handler = require('iris').Handler;
class Handler1 extends Handler {
    constructor(name) {
        super(name);
    }
    get path() {
        return __filename;
    }
    handle(data) {
        this.logger.info('[Handler1] Handling data...');
        return 'A response';
    }
}
module.exports = new Handler1('handler1');
You must implement get path() and process().
Take a look at the base class for a list of the available methods and events.
'use strict';
const Hook = require('iris').Hook;
class Hook1 extends Hook {
    constructor(name) {
        super(name);
    }
    get path() {
        return __filename;
    }
    process(data) {
        this.logger.info('[Hook1] Running...');
    }
}
module.exports = new Hook1('hook1');
Iris exposes a Winston instance at several points, available for full use and configuration:
this.logger.iris.logger.