Welcome to Flask Proxy Server! This project is a powerful and secure proxy server built using Flask. It provides enhanced input validation, domain whitelisting/blacklisting, header management, and IP-based access control, all while being simple to set up and use.
- URL Sanitization & Validation: Ensures only clean and safe URLs are processed.
- Domain Control: Implement domain whitelisting and blacklisting to control access.
- Header Management: Automatically filters out potentially problematic headers.
- IP Access Control: Restrict server access based on IP addresses.
- Request Caching: Cache successful GET requests for faster response times.
- Detailed Logging: Keep track of all requests with comprehensive logging.
Make sure you have Python 3.x installed on your machine.
-
Clone the repository:
git clone https://github.com/ishanoshada/flask-proxy-server.git cd flask-proxy-server
-
Install dependencies:
pip install -r requirements.txt
-
Run the server:
python api/app.py
-
Make your first request: Open your browser or use a tool like Postman to test the proxy:
http://localhost:5000/?url=https://jsonplaceholder.typicode.com/posts
Retrieve data from an external API.
Request:
curl -X GET "http://localhost:5000/?url=https://jsonplaceholder.typicode.com/posts"
Response:
[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit..."
},
...
]
Click to expand
Send data to an external API.
Request:
curl -X POST "http://localhost:5000/?url=https://jsonplaceholder.typicode.com/posts" \
-H "Content-Type: application/json" \
-d '{"title": "foo", "body": "bar", "userId": 1}'
Response:
{
"id": 101,
"title": "foo",
"body": "bar",
"userId": 1
}
Update existing data at an external API.
Request:
curl -X PUT "http://localhost:5000/?url=https://jsonplaceholder.typicode.com/posts/1" \
-H "Content-Type: application/json" \
-d '{"id": 1, "title": "updated title", "body": "updated body", "userId": 1}'
Response:
{
"id": 1,
"title": "updated title",
"body": "updated body",
"userId": 1
}
Delete data at an external API.
Request:
curl -X DELETE "http://localhost:5000/?url=https://jsonplaceholder.typicode.com/posts/1"
Response:
{
"message": "Post deleted successfully"
}
Partially update data at an external API.
Request:
curl -X PATCH "http://localhost:5000/?url=https://jsonplaceholder.typicode.com/posts/1" \
-H "Content-Type: application/json" \
-d '{"title": "patched title"}'
Response:
{
"id": 1,
"title": "patched title",
"body": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"userId": 1
}
Check which HTTP methods are supported by the external API.
Request:
curl -X OPTIONS "http://localhost:5000/?url=https://jsonplaceholder.typicode.com/posts"
Response:
HTTP/1.1 200 OK
Allow: GET, POST, PUT, DELETE, PATCH, OPTIONS
Customize the server's behavior by modifying the following variables in api/app.py
:
-
Allowed Domains:
- Update
WHITELISTED_DOMAINS
andBLACKLISTED_DOMAINS
to control which domains can be accessed.
- Update
-
IP Restrictions:
- Modify
ALLOWED_IPS
to specify which IP addresses can access the server.
- Modify
To deploy this Flask application on Vercel, follow these steps:
-
Login to Vercel: If you don’t have a Vercel account, create one and log in via the CLI.
npm i -g vercel vercel login
-
Deploy the Project: Navigate to your project directory and deploy:
vercel
Follow the prompts to set up your project and select your preferences.
-
Environment Variables: If your application requires any environment variables (like secrets), set them in your Vercel dashboard under the Environment Variables section.
Ensure your proxy works correctly by writing and running tests. Consider using tools like pytest
to automate your testing process.
This project is licensed under the MIT License.
Contributions are welcome! If you have suggestions for improvements or new features, feel free to create a pull request or open an issue. Let's make this project even better together!
- Thanks to the Flask community for creating such a powerful framework!
If you have any questions or feedback, feel free to reach out:
- GitHub: ishanoshada
Happy coding! 🎉