m360.mw.nodejs

0.0.13 • Public • Published

m360.mw.nodejs

The M360 Nodejs Middleware is a dependency that gets consumed by a NodeJs Server built using one of these frameworks Express, Fastify, and NestJs.

The middleware is developed using native NodeJs and includes interfaces that facilitate using it with the above mentioned frameworks.

Installation


Download the M30 Middleware from GIT and install its dependencies using the following commands:

$ npm install m360.mw.nodejs
$ cd m360.mw.nodejs
$ export NODE_ENV=production
$ npm install

Usage


//example using express
const server = require('express')();
const path = require('path');
const M360Mw = require("m360.mw.nodejs");

//add the M360 middleware
server.use(M360Mw({
    'contract': path.normalize(path.join(__dirname, 'contract.json')),
    'ip': "127.0.0.1",
    'type': 'express',
    'server': server,
    'platform': 'manual',
	
    /**
     * The platform designates the type of hosting platform where this microservice will run.
     * By default, the platform supports manual mode and that refers to deploying the microservice in a virtual machine.
     * If this microservice will run in a container, the middleware offers 2 extra options for Docker & Kubernetes.
     */
}));

//using the middleware
server.get('/settings', function (request, reply) {
	
	//the middleware is auto attached to the request
	request.M360.registry.get(null, (error, registry) => {
		if (error) {
			return reply.send(error);
		} else {
			
			let custom = request.M360.custom.get();
			return reply.send({
				"registry": registry,
				"custom": custom
			});
		}
	});
});

// Run the server!
server.listen(4002, '0.0.0.0', function (err, address) {
	if (err) {
		throw err;
	}
	console.log(`server listening on 0.0.0.0:4002`);
});

Containerized Deployment


Deploying on Docker

When deploying on Docker, please provide the extra options below. Without these options, the handshake between the middleware and the gateway will fail, along with any maintenance operation that gets triggered from the console onto this microservice.

Option Data Type Mandatory Description
platform String YES value equals 'docker'
network String YES value equals the docker network attached to this docker service
service String YES value equals the name of the docker service
containerIP String NO value is the internal IP address of the docker container in the docker service

Example

'platform': 'docker',
'platformOptions': {
    'network': 'mike',
    'service': 'service-express',
    'containerIP': '127.0.0.1'
}

Deploying on Kubernetes

When deploying on Kubernetes, please provide the extra options below. Without these options, the handshake between the middleware and the gateway will fail, along with any maintenance operation that gets triggered from the console onto this microservice.

Option Data Type Mandatory Description
platform String YES value equals 'kubernetes'
namespace String YES value equals the kubernetes namespace where your deployment will run
service String YES value equals the name of the kubernetes service that is attached to the your deployment
exposedPort String YES value equals the exposed port kubernetes service
'platform': 'kubernetes',
'platformOptions": {
    'namespace': 'mike',
    'service': 'service-express',
    'exposedPort': 30402
}

The Middleware includes examples on how you can consume it with these servers.

These examples are located inside the frameworks folder in this repository.

Reference: M360 Middleware Official Documentation

Package Sidebar

Install

npm i m360.mw.nodejs

Weekly Downloads

2

Version

0.0.13

License

apache-2.0

Unpacked Size

304 kB

Total Files

48

Last publish

Collaborators

  • ejvaldez360
  • mikehajj85