Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,30 +3,25 @@ import requests
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
-
@app.route('/
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
if not target_url:
|
| 11 |
return jsonify({"error": "No URL provided"}), 400
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
|
| 15 |
-
response = requests.get(target_url, headers={"Cache-Control": "no-cache", "Pragma": "no-cache"})
|
| 16 |
return jsonify({
|
| 17 |
"status_code": response.status_code,
|
| 18 |
"content": response.text
|
| 19 |
-
})
|
| 20 |
except Exception as e:
|
| 21 |
return jsonify({"error": str(e)}), 500
|
| 22 |
|
| 23 |
-
# Prevent caching of responses from this API
|
| 24 |
-
@app.after_request
|
| 25 |
-
def add_no_cache_headers(response):
|
| 26 |
-
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0"
|
| 27 |
-
response.headers["Pragma"] = "no-cache"
|
| 28 |
-
response.headers["Expires"] = "-1"
|
| 29 |
-
return response
|
| 30 |
-
|
| 31 |
if __name__ == "__main__":
|
| 32 |
-
app.run(host=
|
|
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
+
@app.route('/')
|
| 7 |
+
def home():
|
| 8 |
+
return "Welcome to the Flask URL Fetcher!"
|
| 9 |
+
|
| 10 |
+
@app.route('/fetch', methods=['POST'])
|
| 11 |
+
def fetch_url_content():
|
| 12 |
+
data = request.json
|
| 13 |
+
target_url = data.get('url')
|
| 14 |
if not target_url:
|
| 15 |
return jsonify({"error": "No URL provided"}), 400
|
| 16 |
|
| 17 |
try:
|
| 18 |
+
response = requests.get(target_url)
|
|
|
|
| 19 |
return jsonify({
|
| 20 |
"status_code": response.status_code,
|
| 21 |
"content": response.text
|
| 22 |
+
})
|
| 23 |
except Exception as e:
|
| 24 |
return jsonify({"error": str(e)}), 500
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
if __name__ == "__main__":
|
| 27 |
+
app.run(host='0.0.0.0', port=7860)
|