import re, os src = r'd:\backmind_os\batchmind_os\frontend\src' files_fixed = [] for root, dirs, files in os.walk(src): for f in files: if f.endswith(('.jsx', '.js')) and f != 'api.js': path = os.path.join(root, f) with open(path, 'r', encoding='utf-8') as fh: content = fh.read() if 'http://localhost:8000' in content: new_content = content # Add API_BASE import if not already present if 'API_BASE' not in new_content: if "import axios from 'axios';" in new_content: new_content = new_content.replace( "import axios from 'axios';", "import axios from 'axios';\nimport { API_BASE } from '../api/api';" ) else: # Add at top new_content = "import { API_BASE } from '../api/api';\n" + new_content # Replace string literals new_content = new_content.replace("'http://localhost:8000'", 'API_BASE') new_content = new_content.replace('"http://localhost:8000"', 'API_BASE') # Fix template literals like `http://localhost:8000/something/${id}` new_content = re.sub( r'`http://localhost:8000(/[^`]*)`', r'`${API_BASE}\1`', new_content ) with open(path, 'w', encoding='utf-8') as fh: fh.write(new_content) files_fixed.append(f) print('Fixed files:', files_fixed)