New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mux-router

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mux-router

Get the avaliable routes on your Micro Service Node App and import the same routes in other Gateway Node App.

latest
Source
npmnpm
Version
1.0.10
Version published
Maintainers
1
Created
Source

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

Keywords

mux-router

FAQs

Package last updated on 11 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts