Skip to content

Update index.py #1098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions python/flask3/api/index.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
from flask import Flask
from flask import Flask, request, Response, jsonify
import requests

app = Flask(__name__)

@app.route('/')
def home():
return 'Hello, World!'
# Base route for proxying
@app.route('/<path:target_url>', methods=['GET', 'POST', 'PUT', 'DELETE'])
def proxy(target_url):
try:

full_url = target_url

# Extract headers from the incoming request
headers = {"User-Agent":" Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"}



# Forward the request to the target URL
response = requests.request(
method=request.method,
url=full_url,
headers=headers
)

return Response(response.content, response.status_code, response_headers)

except Exception as e:
# Handle errors gracefully
return jsonify({"error": "Failed to proxy the request", "details": str(e)}), 500


@app.route('/about')
def about():
return 'About'