Expressive Socket middleware framework for node.js to make web applications and APIs like a real HTTP middleware framework.
Fireflyio server
Fireflyio client
Fireflyio module router
Fireflyio module monitoring
Fireflyio module ui-monitoring
$ unavaible
const Fireflyio = require('fireflyio');
const app = new Fireflyio();
// response
app.use(ctx => {
ctx.body = 'Hello Fireflyio';
});
app.listen(3000);
Fireflyio is a middleware framework that can take two different kinds of functions as middleware:
- async function
- common function
Here is an example of logger middleware with each of the different functions:
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
// Middleware normally takes two parameters (ctx, next), ctx is the context for one request,
// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.
app.use((ctx, next) => {
const start = Date.now();
return next().then(() => {
const ms = Date.now() - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
});
Add the module in fireflyio
.
const Fireflyio = require('fireflyio');
const FireflyioMonitoring = require('fireflyio-monitoring');
const app = new Fireflyio();
const options = {};
app.extend(FireflyioMonitoring, options);
// ...
The module works like a real REST API but the communication is via the socket protocol.
app.socket
give you more control about the native socket.
All the events available is bellow :
Name event | Description |
---|---|
ready | Called when the socket server is ready |
clientConnected | Called for each new client connection |
clientDisconnected | Called for each disconnect client |
clientAuthenticated | Called for each new authentication |
Emit the specific event for each clients.
const app = new Fireflyio(options: object);
Name parameter | Type | Default | Description |
---|---|---|---|
debug | boolean |
false |
Enable debug mode |
secure | boolean |
false |
Enable Secure mode |
https | boolean |
false |
Enable HTTPS mode (same as secure ) |
ssl | boolean |
false |
Enable SSL mode (same as secure ) |
allowedHttpRequests | boolean |
false |
Allow HTTP(S) requests in the same way that socket requests |
blackListHttpRequests | Array<route: string> |
[] |
Deny HTTP(S) requests only for those routes |
whiteListHttpRequests | Array<route: string> |
[] |
Allow HTTP(S) requests only for those routes |
server | object |
undefined |
HTTP or HTTPS configuration |
socket | object |
undefined |
Socket.io configuration |
Please help us to improve the project by contributing :)
$ npm install
$ npm test