Skip to content

Commit

Permalink
fix: cors 에러 해결
Browse files Browse the repository at this point in the history
- localhost와 remote server 추가
- 추후 dotenv multi value 깔끔하게 해결 필요
  • Loading branch information
sukkyun2 committed Jul 1, 2024
1 parent 91fb93f commit 6dd7a54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
HISTORY_API_HOST=http://3.34.196.131:8080
YOLO_WEIGHT_PATH=yolov5su.pt
YOLO_WEIGHT_PATH=yolov5su.pt
ALLOW_ORIGINS=http://localhost;http://13.124.103.220
5 changes: 3 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@


class Settings(BaseSettings):
history_api: str = Field(alias='HISTORY_API_HOST', default='http://127.0.0.1:8080')
yolo_weight_path: str = Field(default='yolov5su.pt')
history_api: str = Field(alias='HISTORY_API_HOST', default='http://localhost:8080')
yolo_weight_path: str = Field(alias='YOLO_WEIGHT_PATH', default='yolov5su.pt')
allow_origins: str = Field(alias='ALLOW_ORIGINS', default='') # TODO Convert to List

class Config:
env_file = '.env'
Expand Down
10 changes: 10 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
from PIL import Image
from fastapi import FastAPI
from fastapi import UploadFile, File
from fastapi.middleware.cors import CORSMiddleware

from app.api_response import ApiListResponse
from app.config import settings
from app.detection import Detection
from app.history import HistorySaveRequest, save_history
from model.detect import detect

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=settings.allow_origins.split(';'),
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


def convert(result: dict):
return Detection(**result)
Expand Down

0 comments on commit 6dd7a54

Please sign in to comment.