| 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) |