Refactor all function editor front end html + js into a single jinja template (also slight improvement to look of response/logs)
This commit is contained in:
32
app.py
32
app.py
@@ -16,27 +16,21 @@ db = DataBase(app)
|
||||
|
||||
API_URL = 'https://isolator.peterstockings.com/execute'
|
||||
|
||||
DEFAULT_FUNCTION_NAME = 'foo'
|
||||
|
||||
DEFAULT_SCRIPT = """async (req) => {
|
||||
console.log('hello world...')
|
||||
console.log(`Hello ${environment.name}`)
|
||||
return HtmlResponse(
|
||||
`<div>
|
||||
<h1>Method:${req.method}</h1>
|
||||
<h3>Headers</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Key</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
${Object.entries(req.headers).map(([key, value]) =>
|
||||
`<tr>
|
||||
<td>${key}</td>
|
||||
<td>${value}</td>
|
||||
</tr>`)}
|
||||
</table>
|
||||
<pre>${JSON.stringify(req.body, null, 2)}</pre>
|
||||
<h3>Hello ${environment.name}</h3>
|
||||
</div>`)
|
||||
}"""
|
||||
|
||||
DEFAULT_ENVIRONMENT = """{
|
||||
"name": "Peter"
|
||||
}"""
|
||||
|
||||
def map_isolator_response_to_flask_response(response):
|
||||
"""
|
||||
Maps a Node.js response to a Flask response.
|
||||
@@ -59,7 +53,7 @@ def map_isolator_response_to_flask_response(response):
|
||||
|
||||
@ app.route("/", methods=["GET"])
|
||||
def home():
|
||||
return render_template("home.html", script=DEFAULT_SCRIPT)
|
||||
return render_template("home.html", name='Try me', script=DEFAULT_SCRIPT, environment_info=DEFAULT_ENVIRONMENT)
|
||||
|
||||
@ app.route("/client/<function>", methods=["GET"])
|
||||
def client(function):
|
||||
@@ -84,9 +78,7 @@ def dashboard_http_functions():
|
||||
|
||||
@ app.route("/dashboard/http_functions/add_form", methods=["GET"])
|
||||
def get_http_function_add_form():
|
||||
script=DEFAULT_SCRIPT
|
||||
name = "foo"
|
||||
return render_template("dashboard/http_functions/new.html", name=name, script=script)
|
||||
return render_template("dashboard/http_functions/new.html", name=DEFAULT_FUNCTION_NAME, script=DEFAULT_SCRIPT, environment_info=DEFAULT_ENVIRONMENT)
|
||||
|
||||
@ app.route("/dashboard/http_functions/create", methods=["POST"])
|
||||
def create_http_function():
|
||||
@@ -168,9 +160,11 @@ def execute_code():
|
||||
'url': request.url,
|
||||
# Add other request properties as needed
|
||||
}
|
||||
environment = request.json.get('environment_info')
|
||||
environment_json = json.loads(environment)
|
||||
|
||||
# Call the Node.js API
|
||||
response = requests.post(API_URL, json={'code': code, 'request': request_obj})
|
||||
response = requests.post(API_URL, json={'code': code, 'request': request_obj, 'environment': environment_json})
|
||||
response_data = response.json()
|
||||
|
||||
# check if playground=true is in the query string
|
||||
|
||||
Reference in New Issue
Block a user