About
https://www.npmjs.com/package/http-proxy is a What is an HTTP Proxy?
Articles Related
Example
const { createServer } = require('http')
const httpProxy = require('http-proxy')
const { parse } = require('url')
const proxy = httpProxy.createProxyServer()
const target = 'http://localhost:3001'
createServer((req, res) => {
const parsedUrl = parse(req.url, true)
const { pathname, query } = parsedUrl
switch (pathname) {
case '/api/login.js':
proxy.web(req, res, { target }, error => {
console.log('Error!', error)
})
break
default:
handle(req, res, parsedUrl)
break
}
}).listen(3000, err => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
})