Skip to content

dobobaie/fireflyio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[BETA] fireflyio

Expressive Socket middleware framework for node.js to make web applications and APIs like a real HTTP middleware framework.

🚀 Fireflyio

Fireflyio server
Fireflyio client
Fireflyio module router
Fireflyio module monitoring
Fireflyio module ui-monitoring

☁️ Installation

$ unavaible

👋 Hello fireflyio

const Fireflyio = require('fireflyio');
const app = new Fireflyio();
 
// response
app.use(ctx => {
  ctx.body = 'Hello Fireflyio';
});
 
app.listen(3000);

⚙️ Middleware

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:

async functions (node v7.6+)

app.use(async (ctx, next) => {
  const start = Date.now();
  await next();
  const ms = Date.now() - start;
  console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});

Common function

// 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`);
  });
});

💻 Modules extension

extend(module: any, options: object)

Add the module in fireflyio.

const Fireflyio = require('fireflyio');
const FireflyioMonitoring = require('fireflyio-monitoring');

const app = new Fireflyio();

const options = {};
app.extend(FireflyioMonitoring, options);

// ...

📝 Socket

How it works ?

The module works like a real REST API but the communication is via the socket protocol.

app.socket

app.socket give you more control about the native socket.

app.socket.on(event: string, callback: Function)

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

app.socket.diffuse(event: string, data: any)

Emit the specific event for each clients.

⚙️ Options

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

👥 Contributing

Please help us to improve the project by contributing :)

❓️ Testing

$ npm install
$ npm test

About

Expressive socket middleware framework for node.js to make web applications and APIs like a real HTTP middleware framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published