1.0.10 • Published 5 years ago

mux-router v1.0.10

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

Mux Router

It's a node module for Micro Services to get avaliable routes and import them in other Gateway App.

Installation

$ npm install --save mux-router

How to export your app routes in your micro service

const express = require('express');
const { Router } = require('express');
const mux = require('mux-router').muxRouter;

const app = express();
const router = Router();

// The routes of your app
router.get('/users', function (req, res) {
  res.send([{ name: 'Thor', email: 'thor@asgard.com' }]);
});

router.get('/clients', function (req, res) {
  res.send([{ name: 'Tony Stark', email: 'tony@starkindustries.com' }]);
});

// Export your app routes using mux
// The routers of your app will be avaliable on http://localhost:3000/mux-router/routes
mux.generateRoutes([router]);

app.use('/', router);

// Set app to use routes of mux to create the route /mux-router/routes
app.use('/', mux.router);

app.listen(3000);

How to import the routes of other app in your gateway server

const express = require('express');
const mux = require('mux-router').muxRouter;
const app = express();

// Import the routes of other app to use
mux.generateRequests('http://localhost:3000', (req, res, next) => {
  console.log('Redirecting to other app');
  
  // Here you can choose to which url redirect the requests
  mux.redirect('http://localhost:3000', req, res, next);
});

// Set app to use imported routes in other app using mux
app.use('/', mux.router);

app.listen(3001);

Methods

  • generateRoutes(Array of express routers);
  • generateRequests(urlRepository, (request, response, nextFunction) => { });
  • redirect(urlToRedirectRequests, request, response, nextFunction);

Tests

To run the test suite, first install the dependencies, then run npm run test:

$ npm install
$ npm run test

License

MIT

1.0.10

5 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago