0.0.13 • Published 1 year ago

m360.mw.nodejs v0.0.13

Weekly downloads
-
License
apache-2.0
Repository
bitbucket
Last release
1 year ago

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.

OptionData TypeMandatoryDescription
platformStringYESvalue equals 'docker'
networkStringYESvalue equals the docker network attached to this docker service
serviceStringYESvalue equals the name of the docker service
containerIPStringNOvalue 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.

OptionData TypeMandatoryDescription
platformStringYESvalue equals 'kubernetes'
namespaceStringYESvalue equals the kubernetes namespace where your deployment will run
serviceStringYESvalue equals the name of the kubernetes service that is attached to the your deployment
exposedPortStringYESvalue 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

0.0.12

1 year ago

0.0.13

1 year ago

0.0.10

2 years ago

0.0.11

1 year ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

3 years ago