Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions gdbui_server/.env.example
Original file line number Diff line number Diff line change
@@ -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/
15 changes: 10 additions & 5 deletions gdbui_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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})
Expand Down Expand Up @@ -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',
)