This project configures an HTTP proxy server using Node.js, Express, and http-proxy. It is designed to forward requests from a frontend application to a backend API, manage CORS issues, and provide basic logging capabilities.
These instructions will guide you through setting up and running the project on your local machine for development and testing purposes.
Ensure you have the following installed:
Follow these steps to set up your development environment:
- Clone the repository:
git clone https://github.com/edrianolima/http_proxy_server
- Navigate to the repository directory:
cd http_proxy_server - Install the required packages:
npm install
Configure the server by updating the proxy settings:
-
Target API URL: Replace
'https://target-api.com'in theproxyTargetvariable with your actual backend API URL. -
Base Target Endpoint: Modify
/base-target-endpoint/*in the route configuration to your backend base endpoint:const proxyTarget = 'https://target-api.com'; // Replace with your backend URL app.all('/base-target-endpoint/*', (req, res) => { // Replace with your backend Base target endpoint proxy.web(req, res, { target: proxyTarget, timeout: 60000 }); });
To launch the server, execute:
npm startAlternatively, for development with automatic restarts, you can use:
npm run devThe server will initialize on port 4000, or another port if configured differently.
Check the health of the proxy server by visiting:
http://localhost:4000/healthThis will display the server uptime and a status message about the server's health.
To deploy this proxy server using Docker, follow these steps:
- Build the Docker image:
docker build -t http-proxy-server . - Run the container:
docker run -p 4000:4000 http-proxy-server
This will start the server in a Docker container and expose it on port 4000 of your host machine.
- Express - Web framework
- http-proxy - HTTP proxying library
- Edriano Lima - edrianolima
This project is licensed under the ISC License - see the LICENSE file for details.