From bbbe641068535ac733e980390aec6216c721cccf Mon Sep 17 00:00:00 2001 From: alikhere Date: Wed, 25 Mar 2026 04:45:18 +0530 Subject: [PATCH 1/3] docs(backend): add .env.example for backend environment variables --- gdbui_server/.env.example | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 gdbui_server/.env.example diff --git a/gdbui_server/.env.example b/gdbui_server/.env.example new file mode 100644 index 0000000..a9f906b --- /dev/null +++ b/gdbui_server/.env.example @@ -0,0 +1,13 @@ +# Host and port the Flask server binds to. +FLASK_HOST=0.0.0.0 +FLASK_PORT=10000 + +# Set to 1 to enable Flask debug mode. Use 0 in production. +FLASK_DEBUG=0 + +# Comma-separated list of allowed CORS origins. +# Use * to allow all origins (development default). +CORS_ORIGINS=* + +# Directory where compiled and uploaded binaries are stored. +OUTPUT_DIR=output/ From 0d473298ee77ee942205cff2fd289e449216d4fe Mon Sep 17 00:00:00 2001 From: alikhere Date: Wed, 25 Mar 2026 04:45:30 +0530 Subject: [PATCH 2/3] feat(backend): read host, port, debug, CORS, and output dir from env --- gdbui_server/main.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gdbui_server/main.py b/gdbui_server/main.py index 6539127..f194f92 100644 --- a/gdbui_server/main.py +++ b/gdbui_server/main.py @@ -5,11 +5,12 @@ import os app = Flask(__name__) -cors = CORS(app) +cors = CORS(app, origins=os.environ.get('CORS_ORIGINS', '*')) app.config['CORS_HEADERS'] = 'Content-Type' gdb_controller = None program_name = None +output_dir = os.environ.get('OUTPUT_DIR', 'output/') def execute_gdb_command(command): response2 = gdb_controller.write(command) @@ -32,7 +33,7 @@ def start_gdb_session(program): raise RuntimeError(f"Failed to initialize GDB controller: {e}") try: - response = gdb_controller.write(f"-file-exec-and-symbols {os.path.join('output/', ensure_exe_extension(program_name))}") + response = gdb_controller.write(f"-file-exec-and-symbols {os.path.join(output_dir, ensure_exe_extension(program_name))}") if response is None: raise RuntimeError("No response from GDB controller") except Exception as e: @@ -80,7 +81,7 @@ def compile_code(): with open(f'{name}.cpp', 'w') as file: file.write(code) - result = subprocess.run(['g++', f'{name}.cpp', '-o', f'output/{name}.exe'], capture_output=True, text=True) + result = subprocess.run(['g++', f'{name}.cpp', '-o', f'{output_dir}{name}.exe'], capture_output=True, text=True) if result.returncode == 0: program_name = None @@ -99,7 +100,7 @@ def upload_file(): if file.filename == '': return jsonify({'success': False, 'error': 'No selected file'}), 400 - file_path = os.path.join('output/', ensure_exe_extension(name)) + file_path = os.path.join(output_dir, ensure_exe_extension(name)) file.save(file_path) return jsonify({'success': True, 'message': 'File uploaded successfully', 'file_path': file_path}) @@ -446,4 +447,8 @@ def delete_breakpoint(): if __name__ == '__main__': - app.run(host='0.0.0.0', port=10000) + app.run( + host=os.environ.get('FLASK_HOST', '0.0.0.0'), + port=int(os.environ.get('FLASK_PORT', 10000)), + debug=os.environ.get('FLASK_DEBUG', '0') == '1', + ) From 31f0081f5cd4103d3f35b2696623227e89bf1f5a Mon Sep 17 00:00:00 2001 From: alikhere Date: Wed, 25 Mar 2026 04:56:21 +0530 Subject: [PATCH 3/3] update README.md --- README.md | 27 +++++++++++++++++++++++++++ gdbui_server/main.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4bf6a9..c41c40a 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,33 @@ If you prefer a manual setup or are unable to use Docker, follow these steps: python main.py ``` +## Environment Variables + +Both services are configured via `.env` files. Before running locally, copy the example files and adjust any values you need to change: + +```sh +cp webapp/.env.example webapp/.env +cp gdbui_server/.env.example gdbui_server/.env +``` + +**`webapp/.env`** + +| Variable | Default | Description | +|---|---|---| +| `VITE_API_BASE_URL` | `http://127.0.0.1:10000` | URL of the backend server | + +**`gdbui_server/.env`** + +| Variable | Default | Description | +|---|---|---| +| `FLASK_HOST` | `0.0.0.0` | Host the Flask server binds to | +| `FLASK_PORT` | `10000` | Port the Flask server listens on | +| `FLASK_DEBUG` | `0` | Set to `1` to enable Flask debug mode | +| `CORS_ORIGINS` | `*` | Comma-separated list of allowed CORS origins | +| `OUTPUT_DIR` | `output/` | Directory for compiled and uploaded binaries | + +The `.env` files are git-ignored and never committed. The `.env.example` files are the source of truth for what each service expects. + ## Running Tests ### Frontend Tests (Vite) diff --git a/gdbui_server/main.py b/gdbui_server/main.py index f194f92..1f2fbff 100644 --- a/gdbui_server/main.py +++ b/gdbui_server/main.py @@ -451,4 +451,4 @@ def delete_breakpoint(): host=os.environ.get('FLASK_HOST', '0.0.0.0'), port=int(os.environ.get('FLASK_PORT', 10000)), debug=os.environ.get('FLASK_DEBUG', '0') == '1', - ) + ) \ No newline at end of file