simple look
This commit is contained in:
@@ -2,6 +2,7 @@ from flask import Flask, request, jsonify
|
|||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@@ -11,12 +12,19 @@ TARGET_URL = os.getenv('TARGET_URL', 'http://host.docker.internal:8545')
|
|||||||
@app.route('/', methods=['POST'])
|
@app.route('/', methods=['POST'])
|
||||||
def proxy():
|
def proxy():
|
||||||
incoming = request.get_json()
|
incoming = request.get_json()
|
||||||
print(f"==> Request:\n{incoming}", file=sys.stdout, flush=True)
|
request_log = f"==> Request:\n{json.dumps(incoming, indent=2)}"
|
||||||
|
|
||||||
response = requests.post(TARGET_URL, json=incoming)
|
response = requests.post(TARGET_URL, json=incoming)
|
||||||
outgoing = response.json()
|
outgoing = response.json()
|
||||||
|
|
||||||
print(f"<== Response:\n{outgoing}", file=sys.stdout, flush=True)
|
log_lines = [request_log]
|
||||||
|
|
||||||
|
if 'error' in outgoing:
|
||||||
|
response_log = f"<== Response (Error):\n{json.dumps(outgoing, indent=2)}"
|
||||||
|
log_lines.append(response_log)
|
||||||
|
|
||||||
|
print('\n---\n'.join(log_lines), file=sys.stdout, flush=True)
|
||||||
|
|
||||||
return jsonify(outgoing)
|
return jsonify(outgoing)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user