O'Reilly logo

TypeScript Microservices by Parth Ghiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

HTTP proxy and Express Gateway

HTTP proxy is an HTTP programmable library for proxying. This is helpful for applying things such as reverse proxy or load balancing. http-proxy available in npm has more than 1 lakh download per day. To achieve request dispatching we can use http-proxy. This is a piece of cake and can be achieved like this:

const express = require('express')const httpProxy = require('express-http-proxy')const app = express();const productServiceProxy= httpProxy('https://10.0.0.1/') //10.0.0.1 is product container location// Authenticationapp.use((req, res, next) => {    // TODO: Central Authentication logic for all    next()    })// Proxy requestapp.get('/products/:productId', (req, res, next) => { productServiceProxy(req, res, next) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required