diff --git a/app.py b/app.py new file mode 100644 index 0000000..16dac32 --- /dev/null +++ b/app.py @@ -0,0 +1,57 @@ +import sys +import os +import subprocess +import http.server +import socketserver +import threading + +PORT = int(os.environ.get('SERVER_PORT') or os.environ.get('PORT') or 3000) # 定义端口 + +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("./temp/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") + print("Thank you for using this script,enjoy!") + +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() \ No newline at end of file