Spaces:
Sleeping
Sleeping
Download hf-space/patch_cors.py from shaun07/grid-backtest: direct link, hf CLI and curl.
- Browser
- Download file 682 Bytes
-
https://huggingface.co/spaces/shaun07/grid-backtest/resolve/main/hf-space/patch_cors.py
- Command line
-
hf download hf://spaces/shaun07/grid-backtest/hf-space/patch_cors.py
-
curl -L -o patch_cors.py https://huggingface.co/spaces/shaun07/grid-backtest/resolve/main/hf-space/patch_cors.py
682 Bytes
| """ | |
| 补丁脚本:更新 CORS 配置,允许 HuggingFace Spaces 域名访问。 | |
| """ | |
| import re | |
| filepath = '/app/backend/server.py' | |
| with open(filepath, 'r') as f: | |
| content = f.read() | |
| # 替换 CORS allow_origins 行 | |
| old_cors = '''allow_origins=["http://localhost:3000", "http://127.0.0.1:3000", "http://localhost:3001", "http://127.0.0.1:3001"],''' | |
| new_cors = '''allow_origins=["*"], # HF Spaces: 允许所有来源''' | |
| if old_cors in content: | |
| content = content.replace(old_cors, new_cors) | |
| print('✅ CORS 补丁已应用:允许所有来源') | |
| else: | |
| print('⚠️ 未找到 CORS 配置,可能已被修改') | |
| with open(filepath, 'w') as f: | |
| f.write(content) | |