Change function name to path so you can pass in sub paths to executing code

This commit is contained in:
Peter Stockings
2023-12-22 10:11:17 +11:00
parent 34186d25a0
commit 6fab33ea2b

13
app.py
View File

@@ -227,10 +227,15 @@ def execute_code():
except Exception as e: except Exception as e:
return jsonify({'error': str(e)}), 500 return jsonify({'error': str(e)}), 500
@app.route('/f/<int:user_id>/<function>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD']) @app.route('/f/<int:user_id>/<path:function>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'])
def execute_http_function(user_id, function): def execute_http_function(user_id, function):
try: try:
http_function = db.get_http_function(user_id, function) # Split the function_path into the function name and the sub-path
parts = function.split('/', 1)
function_name = parts[0]
sub_path = '/' + parts[1] if len(parts) > 1 else '/'
http_function = db.get_http_function(user_id, function_name)
if not http_function: if not http_function:
return jsonify({'error': 'Function not found'}), 404 return jsonify({'error': 'Function not found'}), 404
@@ -252,7 +257,7 @@ def execute_http_function(user_id, function):
'method': request.method, 'method': request.method,
'headers': dict(request.headers), 'headers': dict(request.headers),
'url': request.url, 'url': request.url,
# Add other request properties as needed 'path': sub_path,
} }
# Add JSON data if it exists # Add JSON data if it exists
@@ -275,7 +280,7 @@ def execute_http_function(user_id, function):
response = requests.post(API_URL, json={'code': code, 'request': request_data, 'environment': environment}) response = requests.post(API_URL, json={'code': code, 'request': request_data, 'environment': environment})
response_data = response.json() response_data = response.json()
db.update_http_function_environment_info_and_invoked_count(user_id, function, response_data['environment']) db.update_http_function_environment_info_and_invoked_count(user_id, function_name, response_data['environment'])
db.add_http_function_invocation( db.add_http_function_invocation(
http_function['id'], http_function['id'],
response_data['status'], response_data['status'],