This repository contains a simple reverse proxy setup using FastAPI for handling API requests and ngrok for creating a public tunnel to the local server.
api.py: A FastAPI application with CORS middleware and a custom header middleware.proxy_server.py: A script to start an ngrok tunnel and redirect traffic to the FastAPI server.
- Python 3.7+
- FastAPI
- Uvicorn
- ngrok
-
Clone the repository:
git clone https://github.com/yourusername/reverse-proxy.git cd reverse-proxy -
Install the required packages:
pip install fastapi uvicorn requests
-
Ensure you have ngrok installed. If not, download it from ngrok's official website and follow the installation instructions.
-
Set up your ngrok auth token:
ngrok authtoken YOUR_NGROK_AUTH_TOKEN
- Update the
NGROK_AUTH_TOKENinproxy_server.pywith your ngrok auth token.
-
Start the FastAPI server:
python api.py
-
In another terminal, start the ngrok tunnel using the provided script:
python proxy_server.py
The script will start ngrok and redirect traffic to the FastAPI server running on port 3000. It will also log the public ngrok URL.
- GET /: Returns a simple JSON message with the client's IP and request path.
The FastAPI application includes the following middleware:
- CORS Middleware: Allows all origins for testing purposes.
- Custom Header Middleware: Adds a custom header to bypass local tunnel restrictions.
Both api.py and proxy_server.py are configured with basic logging to track incoming requests and ngrok tunnel status.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to modify the configurations and endpoints as per your requirements. Contributions and suggestions are welcome!