Compare commits
4 Commits
worktree-y
...
fb759ebe33
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb759ebe33 | ||
|
|
b9e13105e1 | ||
|
|
70cb6759ea | ||
|
|
f94a18fee7 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,3 +7,6 @@ dist/
|
||||
build/
|
||||
.pytest_cache/
|
||||
.claude/
|
||||
|
||||
# Local configuration overrides
|
||||
config/settings.local.yaml
|
||||
22
README.md
22
README.md
@@ -11,3 +11,25 @@ source .venv/bin/activate # Linux/Mac
|
||||
pip install -r requirements.txt
|
||||
uvicorn app.main:app --reload
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Configuration is managed via YAML files in the `config/` directory.
|
||||
|
||||
### Configuration File
|
||||
|
||||
Edit `config/settings.yaml` to configure your environment:
|
||||
|
||||
```yaml
|
||||
database:
|
||||
sql_server:
|
||||
host: your-host
|
||||
port: 1433
|
||||
database: your-database
|
||||
username: your-username
|
||||
password: your-password
|
||||
```
|
||||
|
||||
### Local Overrides
|
||||
|
||||
For local development, create `config/settings.local.yaml` to override specific values without committing them.
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
from sqlalchemy.engine import URL
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
SQL_SERVER_HOST: str
|
||||
SQL_SERVER_PORT: int = 1433
|
||||
SQL_SERVER_DATABASE: str
|
||||
SQL_SERVER_USERNAME: str
|
||||
SQL_SERVER_PASSWORD: str
|
||||
SQL_SERVER_DRIVER: str = "{ODBC Driver 18 for SQL Server}"
|
||||
SQL_SERVER_TRUST_SERVER_CERTIFICATE: str = "yes"
|
||||
|
||||
@property
|
||||
def database_url(self) -> URL:
|
||||
return URL.create(
|
||||
"mssql+pyodbc",
|
||||
username=self.SQL_SERVER_USERNAME,
|
||||
password=self.SQL_SERVER_PASSWORD,
|
||||
host=self.SQL_SERVER_HOST,
|
||||
port=self.SQL_SERVER_PORT,
|
||||
database=self.SQL_SERVER_DATABASE,
|
||||
query={
|
||||
"driver": self.SQL_SERVER_DRIVER.strip("{}"),
|
||||
"TrustServerCertificate": self.SQL_SERVER_TRUST_SERVER_CERTIFICATE,
|
||||
},
|
||||
)
|
||||
|
||||
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
|
||||
|
||||
|
||||
settings = Settings()
|
||||
14
app/main.py
14
app/main.py
@@ -1,7 +1,21 @@
|
||||
import sys
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from config.settings import load_settings
|
||||
|
||||
# 加载配置文件,失败则退出
|
||||
try:
|
||||
settings = load_settings()
|
||||
except FileNotFoundError as e:
|
||||
print(f"配置文件错误: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"加载配置失败: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
from app.api.v1.location import router as location_router
|
||||
from app.api.v1.box import router as box_router
|
||||
from app.services.location_service import DuplicateLocationError
|
||||
|
||||
Reference in New Issue
Block a user