Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, jsonify, request
|
| 2 |
+
|
| 3 |
+
app = Flask(__name__)
|
| 4 |
+
|
| 5 |
+
API_KEY = "MY_SECRET_KEY_123" # replace with your custom key
|
| 6 |
+
|
| 7 |
+
@app.before_request
|
| 8 |
+
def check_api_key():
|
| 9 |
+
provided = request.headers.get("X-API-Key") or request.args.get("api_key")
|
| 10 |
+
if provided != API_KEY:
|
| 11 |
+
return jsonify({"error": "Unauthorized"}), 401
|
| 12 |
+
|
| 13 |
+
@app.route("/", methods=["GET"])
|
| 14 |
+
def hello():
|
| 15 |
+
return jsonify({"message": "Hello, World!", "source": "Flask on Hugging Face Spaces"})
|
| 16 |
+
|
| 17 |
+
@app.route("/ping", methods=["GET"])
|
| 18 |
+
def ping():
|
| 19 |
+
return jsonify({"ok": True, "path": "ping"})
|