INPORTANT NOTICE A Microservices API Gateway Built Using Express.js and Express Middleware. Micro gateway is a simple customizable gateway server.
- add .env int root folder
- add PORT variable
PORT=8080
- add proxy routes object in ROUTES Array in config/routes.js
# Example object array let Routes = [{ url: '/todos', authServices: [auth.checkForAuth,auth.checkForAuth2], creditCheck: false, proxy: { target: "https://jsonplaceholder.typicode.com", changeOrigin: true, pathRewrite: { [`^/free`]: '', }, } }]
- options.url : Incomming route, we can use all express wildcard syntx in it.
- authServices : Array of valid middleware function
function middleware(req,res,next){ next(); }
- creditCheck : Bool Value ( InDevelopment )
- proxy : Object
- target : target url
https://jsonplaceholder.typicode.com
- changeOrigin : bool value for cors origin policy
- pathRewrite : to rewrite the url path
// host/free -> proxyhost/api pathRewrite: { [`^/free`]: '/api', }
- we can add multiple rewrite rules
- target : target url
// Example object array
{
url: '/todos',
authServices: [auth.checkForAuth,auth.checkForAuth2],
creditCheck: false,
proxy: {
target: "https://jsonplaceholder.typicode.com",
changeOrigin: true,
pathRewrite: {
[`^/free`]: '',
},
}
}