forked from eooce/Sing-box
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
56 lines (47 loc) · 1.63 KB
/
app.py
File metadata and controls
56 lines (47 loc) · 1.63 KB
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
import sys
import os
import subprocess
import http.server
import socketserver
import threading
PORT = int(os.environ.get('PORT') or 3000) # http port
class MyHandler(http.server.SimpleHTTPRequestHandler):
def log_message(self, format, *args):
pass
def do_GET(self):
if self.path == '/':
self.send_response(200)
self.end_headers()
self.wfile.write(b'Hello, world')
elif self.path == '/sub':
try:
with open("./sub.txt", 'rb') as file:
content = file.read()
self.send_response(200)
self.send_header('Content-Type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write(content)
except FileNotFoundError:
self.send_response(500)
self.end_headers()
self.wfile.write(b'Error reading file')
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b'Not found')
httpd = socketserver.TCPServer(('', PORT), MyHandler)
server_thread = threading.Thread(target=httpd.serve_forever)
server_thread.daemon = True
server_thread.start()
shell_command = "chmod +x start.sh && ./start.sh"
try:
completed_process = subprocess.run(['bash', '-c', shell_command], stdout=sys.stdout, stderr=subprocess.PIPE, text=True, check=True)
print("App is running")
except subprocess.CalledProcessError as e:
print(f"Error: {e.returncode}")
print("Standard Output:")
print(e.stdout)
print("Standard Error:")
print(e.stderr)
sys.exit(1)
server_thread.join()