import http.server import json import os class BridgeHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): if self.path == '/logs': self.send_response(200) self.send_header('Content-type', 'text/plain') self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() if os.path.exists('deploy.log'): with open('deploy.log', 'r') as f: lines = f.readlines() self.wfile.write("".join(lines[-20:]).encode()) return return http.server.SimpleHTTPRequestHandler.do_GET(self) def do_POST(self): content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length) if self.path == '/discovery': with open("live_settings.json", "wb") as f: f.write(post_data) self.send_response(200) self.end_headers() # Signal Bash that discovery data is ready with open(".discovery_ready", "w") as f: f.write("1") elif self.path == '/deploy': with open("../numbus.yaml", "wb") as f: f.write(post_data) self.send_response(200) self.end_headers() with open(".deploy_signal", "w") as f: f.write("1") os.chdir("configurator") http.server.HTTPServer(('localhost', 8088), BridgeHandler).serve_forever()