GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing masteringjs.io — Create a Simple HTTP Proxy in Node.js
☰
Create a Simple HTTP Proxy in Node.js
Oct 30, 2020
The http-proxy package on npm is the most popular way to create an HTTP proxy in Node.js. Below is a standalone script that shows how to use http-proxy with Express, and make a proxied HTTP request using Axios.
The http-proxy package doesn't require you to use Express. You can also use Node's built-in
Modifying RequestsWith a proxy server, there's two HTTP requests: the inbound request that the proxy server received, and the outbound request that the proxy server sends. In the previous examples, the inbound request is the same as the outbound request. However, many proxy servers modify outbound requests. For example, you may want your proxy server to set an HTTP header. In order to modify the outbound request, you need to listen to http-proxy's 'proxyReq' event, which gives you access to the outbound request that http-proxy will send. For example, here's how you can set the 'Authorization' header on all outbound requests:
Did you find this tutorial useful? Say thanks by starring our repo on GitHub!
More Node Tutorials
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |