from flask import Flask, request, Response
import requests
app = Flask(__name__)
@app.route('/', defaults={'path': ''}, methods=["GET", "POST"])
@app.route('/<path>', methods=["GET", "POST"])
def redirect_to_API_HOST(path):
res = requests.request(
method=request.method,
url=request.url.replace(request.host_url, 'https://www.google.com/'),
headers={k: v for k, v in request.headers if k.lower() != 'host'}, # exclude 'host' header
data=request.get_data(),
cookies=request.cookies,
allow_redirects=False,
)
response = Response(res.content, res.status_code)
return response
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, debug=True)