Node - http-proxy

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > Node.js

1 - About

3 - 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')
})
web/javascript/node/http-proxy.txt · Last modified: 2019/05/29 16:59 by gerardnico