dracoox commited on
Commit
c7458b1
·
verified ·
1 Parent(s): f6e6538

Create app.py

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