-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathserver.py
77 lines (68 loc) · 1.96 KB
/
server.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from flask import Flask, send_file, jsonify
from flask_cors import CORS
import random
import os
app = Flask(__name__)
CORS(app)
# Get the directory containing server.py
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
@app.route('/')
def index():
"""Serve index.html from the same directory as server.py"""
return send_file(os.path.join(BASE_DIR, 'index.html'))
@app.route('/api/glitch-effect')
def glitch_effect():
"""API endpoint for glitch effect parameters"""
return jsonify({
'offset': random.randint(-5, 5),
'opacity': random.uniform(0.8, 1.0)
})
# Error handling for missing index.html
@app.errorhandler(404)
def not_found(e):
return """
<!DOCTYPE html>
<html>
<head>
<title>File Not Found</title>
<style>
body {
background-color: #0a0a0a;
color: #00ff9d;
font-family: monospace;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
text-align: center;
}
.error {
padding: 20px;
border: 1px solid #00ff9d;
}
</style>
</head>
<body>
<div class="error">
<h1>Error: index.html not found</h1>
<p>Please ensure index.html exists in the same directory as server.py</p>
</div>
</body>
</html>
""", 404
# Custom error handler for other errors
@app.errorhandler(500)
def server_error(e):
return jsonify(error=str(e)), 500
if __name__ == '__main__':
# Check if index.html exists
if not os.path.exists(os.path.join(BASE_DIR, 'index.html')):
print("Warning: index.html not found in the current directory!")
print(f"Please ensure index.html exists in: {BASE_DIR}")
# Start the server
app.run(
host='0.0.0.0',
port=8933,
debug=True
)