A framework built on Express with built in JWT authentication, Dependency Injection, and Eventing.
There are only a few steps to getting NodeFlare up and running.
npm install --save nodeflare sequelize sqlite3
import {NodeFlare} from 'nodeflare';
let config = {hostname: 'http://localhost', port: 61370, tokenkey: '12345'};
let app = new NodeFlare(config).start();
export default app;
By default, NodeFlare starts up as an empty application listening on the port you configured. You can enable additional features prior to calling .start() on the NodeFlare object.
To enable the authentication services you can call .withAuthServices()
let app = new NodeFlare(config)
.withAuthServices()
.start();
You can configure application settings with .appSet(setting, value). You can set existing Express Settings
let app = new NodeFlare(config)
.appSet('view engine', 'pug')
.start();
You can pass an optional path and function to .appUse(path, function) to add middleware to your application. You can pass in a Router as a function. This will allow you to more easily encapsulate Routers into their own classes.
import {NodeFlare, Router} from 'nodeflare';
let router = new Router();
router.get('/fun', (req, res, next) => {
res.json({message: 'Yay'});
});
let app = new NodeFlare(config)
.appUse('/api', router)
.start();
This will create path /api/fun and will execute the router function.
If you turn on the Authentication Services, by default all new services you create are protected and you must preset a valid auth token. If you wish to allow (whitelist) certain services, you can call .whitelist(string|array).
let app = new NodeFlare(config)
.withAuthServices()
.whitelist('/custom/url')
.start();
When you call start on a NodeFlare object, this creates the Application Context. This is available as global.ctx. You can register your own classes prior to calling start().
let app = new NodeFlare(config)
.register('Name', '<Class>')
.register('Name', '<Class>', ['<Constructor Args>'])
.start();
let app = new NodeFlare(config)
.registerInstance('Name', '<Object Instance>')
.start();
let app = new NodeFlare(config)
.registerAndUse('/custom/url', 'Name', '<Class>', '[Constructor args]')
.registerAndUse('/custom/url', 'Name', '<Class>')
.start();
Onces you have started your application, you can call ctx.get('Name') to get the instance of the class you registered.
You can get a reference to the EventHub from the application context
let eventHub = ctx.get('EventHub');
You can subscribe to events with the key and channel and provide an event handler. Currently only unsubscribing from a key is supported.
let eventHub = ctx.get('EventHub');
eventHub.subscribe(SomeClassName, 'Updated', (data) => {
console.log(data);
});
eventHub.unsubscribe(SomeClassName);
You can publish events to any channel.
let eventHub = ctx.get('EventHub');
eventHub.publish('Updated', {}); // Channel & Payload. Payload is optional
Below is the configuration that is available. The following properties are required, everything else is optional depending on your environment.
- hostname
- port
- tokenkey
{
"hostname": "http://localhost:61370",
"port": 61370,
"tokenkey": "<Some Random>",
"passwordresettoken": "<Some Random>",
"database": {
"type": "<pg|mysql|sqlite>",
"db": "<Database Name>",
"path": "<File path for Sqlite. Empty for in memory>",
"host": "<Hostname for mysql/postgres>",
"user": "<DB User for mysql/postgres>",
"password": "<DB Password for mysql/postgres>"
},
"mail": {
"disabled": true,
"api": "<Api Url for Mail Gun>",
"from": "",
"message": "<Message for the Password Reset Email>",
"subject": "<Password Reset Email Subject>"
}
}
NodeFlare uses Sqlite by default to store users. Through configuration you can specify PostgreSQL or MySQL which are both supported.
Request Object
{
"username": "<User Account Email Address>",
"password": "<Account Password>"
}
Json Response
{"token": "<Authentication Token>", "sessionData": "<Custom Session Data Object>"}
Request Object
{
"emailAddress": "<User Account Email Address>",
"passwordresettoken": "<Token that was provided through configuration>"
}
Json Response
{"token": "<Request Token>", "emailAddress": "<Account Email Address>"}
Json Response
{
"id": "user.id",
"version": "user.version",
"emailAddress": "user.emailAddress"
}
In addition to the above properties, all the properties you specify in the details of the create will be included.
Request Object
{
"emailAddress": "<Email>",
"password": "<Password>",
"details": {} // any data you want stored with the user as an object
}
Json Response
Request Object
{
"id": "<ID>",
"version": "<VERSION>",
"emailAddress": "<Email>",
"details": {} // User object you want to edit.
}
Json Response
Contact [email protected]