File size: 1,398 Bytes
446cb49 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
from flask import Flask, jsonify, render_template_string, request
app = Flask(__name__)
@app.route('/')
def home():
return render_template_string("""
<!DOCTYPE html>
<html>
<head>
<title>Flask on Tailscale</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 100px;
background-color: #f8f9fa;
}
h1 { color: #2c3e50; }
p { color: #555; }
a { color: #007bff; }
</style>
</head>
<body>
<h1>Hello from Flask over Tailscale!</h1>
<p>This is a secure Flask app behind a Tailscale network.</p>
<p>Try the <a href="/api/hello">JSON Hello</a> or POST to <code>/api/echo</code>.</p>
</body>
</html>
""")
@app.route('/api/hello', methods=['GET'])
def api_hello():
return jsonify({
"message": "Hello from the Flask API!",
"status": "success"
})
@app.route('/api/echo', methods=['POST'])
def api_echo():
data = request.get_json()
if not data:
return jsonify({"error": "No JSON received"}), 400
return jsonify({
"received": data,
"status": "ok"
})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860) |