Instruction

All scripts in plugins/ are .js | Every script only in this dir not in sub will intarpretated as plugin.

Structure

Every plugin should contain this:

// plugins/pluginExample.js

// Plugins load automaticly

// Modules
const { renderPage, getAsset, writeRaw, getJson, getRaw } = require('../RocketFramework');
const fs = require('fs');
const path = require('path');

function success() {
    console.warn('ExamplePlugin loaded!') // Just for debug
}

function logic(app) {
    // examplePluginSettings.html

    // Example of handling only "get" requests
    app.get('/plugins/ExamplePlugin/page/ExamplePluginSettings', (req, res) => {
        renderPage('ExamplePluginSettings.html', res); // Here we are rendering page from structure/pages
    });

    // Example of handling only "post" requests
    app.post('/plugins/ExamplePlugin/data/setting', (req, res) => {
      const { name, type, data } = getJson(req); // Use the same order of sending data
      res.send(`Getted setting: ${name}`);
    });
}

// What you must have is below, other for neccessary
module.exports = function (context) {
    // context — object with neccesarry links (conf in route.js) like, app (Express), db and etc.

    // Getting Express.js "router" from router.js
    const app = context.router;

    success();

    logic(app);

    // Same we can use function that we need outside the export for comfort

    // We can use "app" to make new routes to configure something
    // Using the same framework
};

🔙 Previous module

Plugins

Last updated