diff --git a/extra/callback_server.py b/extra/callback_server.py new file mode 100644 index 0000000..1a2302c --- /dev/null +++ b/extra/callback_server.py @@ -0,0 +1,32 @@ +from http.server import HTTPServer, BaseHTTPRequestHandler +import sys, os + +DEFAULT_PORT = int(os.getenv('LOCAL_CALLBACK_PORT', 9888)) + + +class RequestHandler(BaseHTTPRequestHandler): + def do_POST(self): + content_length = int(self.headers['Content-Length']) + post_data = self.rfile.read(content_length) + + print("Received POST request:") + print(post_data.decode('utf-8')) + + self.send_response(200) + self.send_header('Content-type', 'text/plain') + self.end_headers() + self.wfile.write(b"{\"message\": \"Message Received\"}") + + +def run_server(port=DEFAULT_PORT): + server_address = ('', port) + httpd = HTTPServer(server_address, RequestHandler) + print(f"Server running on port {port}") + httpd.serve_forever() + + +if __name__ == '__main__': + port = DEFAULT_PORT + if len(sys.argv) > 1: + port = int(sys.argv[1]) + run_server(port)