feat(server): add extra CORS origins url configuration
This commit is contained in:
@@ -20,6 +20,8 @@ HOST="0.0.0.0"
|
|||||||
PORT=8000
|
PORT=8000
|
||||||
# 服务器 URL
|
# 服务器 URL
|
||||||
SERVER_URL="http://localhost:8000"
|
SERVER_URL="http://localhost:8000"
|
||||||
|
# 额外的 CORS 允许的域名列表
|
||||||
|
CORS_URLS='[]'
|
||||||
# 调试模式,生产环境请设置为 false
|
# 调试模式,生产环境请设置为 false
|
||||||
DEBUG=false
|
DEBUG=false
|
||||||
# 私有 API 密钥,用于前后端 API 调用,使用 openssl rand -hex 32 生成
|
# 私有 API 密钥,用于前后端 API 调用,使用 openssl rand -hex 32 生成
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ docker-compose -f docker-compose-osurx.yml up -d
|
|||||||
| `PORT` | 服务器监听端口 | `8000` |
|
| `PORT` | 服务器监听端口 | `8000` |
|
||||||
| `DEBUG` | 调试模式 | `false` |
|
| `DEBUG` | 调试模式 | `false` |
|
||||||
| `SERVER_URL` | 服务器 URL | `http://localhost:8000` |
|
| `SERVER_URL` | 服务器 URL | `http://localhost:8000` |
|
||||||
|
| `CORS_URLS` | 额外的 CORS 允许的域名列表 (JSON 格式) | `[]` |
|
||||||
| `PRIVATE_API_SECRET` | 私有 API 密钥,用于前后端 API 调用 | `your_private_api_secret_here` |
|
| `PRIVATE_API_SECRET` | 私有 API 密钥,用于前后端 API 调用 | `your_private_api_secret_here` |
|
||||||
|
|
||||||
### OAuth 设置
|
### OAuth 设置
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ class Settings(BaseSettings):
|
|||||||
port: int = 8000
|
port: int = 8000
|
||||||
debug: bool = False
|
debug: bool = False
|
||||||
private_api_secret: str = "your_private_api_secret_here"
|
private_api_secret: str = "your_private_api_secret_here"
|
||||||
|
cors_urls: list[HttpUrl] = []
|
||||||
server_url: HttpUrl = HttpUrl("http://localhost:8000")
|
server_url: HttpUrl = HttpUrl("http://localhost:8000")
|
||||||
|
|
||||||
# SignalR 设置
|
# SignalR 设置
|
||||||
|
|||||||
2
main.py
2
main.py
@@ -48,7 +48,7 @@ app.include_router(private_router)
|
|||||||
# CORS 配置
|
# CORS 配置
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[str(settings.server_url)],
|
allow_origins=[str(url) for url in [*settings.cors_urls, settings.server_url]],
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
|
|||||||
Reference in New Issue
Block a user