Reactium
Search
⌃K

Actinium Domain Model

Artifacts

File
Description
middleware.js
Express middleware file for registering middleware.
plugin.js
Actinium plugin file for registering a plugin.
sdk.js
File in a plugin directory that defines an extension to the Actinium SDK. (optional)
route.js
File in a plugin directory that defines data driven routes for dynamic routes in the admin or another UI application. (optional)
blueprints.js
File in a plugin directory that defines UI layouts for the Admin. (optional)
schema.js
File in a plugin directory that defines DB schema information for registering Parse Collections

plugin.js

Actinium will attempt to add any file within the /src/app directory with a file name that ends with plugin.js and execute in the file scope.
A typical plugin.js file may look like:
/src/app/MyPlugin/plugin.js
const PLUGIN = {
ID: 'MyPlugin',
description: 'My plugin is here!',
name: 'My Plugin',
};
const COLLECTION = 'MyPluginCollection';
// Register plugin
Actinium.Plugin.register(PLUGIN);
// Define a cloud function
Actinium.Cloud.define(PLUGIN.ID, 'my-plugin-log', req => {
console.log(req.params);
return { message: 'OK', status: 200, ...req.params };
});
// Define an after save function that will run an after-save hook
Actinium.Cloud.afterSave(COLLECTION, async req => {
// run this code if MyPlugin is active
if (!Actinium.Plugin.isActive(PLUGIN.ID)) return;
await Actinium.Hook.run(`${COLLECTION}-after-save`, req);
console.log(`Saved a ${COLLECTION} object!`);
});
// Register a start hook
Actinium.Hook.register('start', () => {
// run this code if MyPlugin is active
if (!Actinium.Plugin.isActive(PLUGIN.ID)) return;
console.log(PLUGIN.ID, 'Yo!');
});

middleware.js

Actinium will attempt to add any file within the /src/app directory with a file name that ends with middleware.js and execute it in the file scope.
A typical middleware.js file may look like:
/src/app/MyPlugin/middleware.js
const express = require('express');
const request = require('request');
const op = require('object-path');
const _ = require('underscore');
// Add an Express route hanlder for /media/*
// and serve an Actinium.File object if a matching route is found
Actinium.Middleware.register(
'media',
app => {
const router = express.Router();
router.use('/media/*', (req, res) => {
const p = [80, 443].includes(PORT) ? '' : `:${PORT}`;
const files = Object.values(Actinium.Cache.get('Media.files', {}));
const rec = _.findWhere(files, { url: req.baseUrl });
const fileURL = String(op.get(rec, 'file.url', ''))
.replace('undefined/', `${ENV.ACTINIUM_MOUNT}/`)
.substr(1);
const url = `${req.protocol}://${req.hostname}${p}/${fileURL}`;
request(url).pipe(res);
});
app.use(router);
return Promise.resolve();
},
0,
);
Actinium will traverse node_modules/**/actinium directories for plugin.js and middleware.js artifacts.