Skip to content

Commit

Permalink
fix: CORS 에러 수정 (APAP-ICT#4)
Browse files Browse the repository at this point in the history
* doc: README.md workflow badge 추가

* fix: cors 에러 해결

- localhost와 remote server 추가
- 추후 dotenv multi value 깔끔하게 해결 필요

* fix: cors 에러 해결시 포트 번호 추가

- localhost -> localhost:5173
  • Loading branch information
sukkyun2 authored Jul 5, 2024
1 parent aefb8b7 commit 1acf044
Show file tree
Hide file tree
Showing 4 changed files with 16 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:5173;http://13.124.103.220
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# APAP-AI
[![Deploy with Docker](https://github.com/sukkyun2/APAP-ai/actions/workflows/deploy.yml/badge.svg)](https://github.com/sukkyun2/APAP-ai/actions/workflows/deploy.yml)

This is a repository for an object detection inference API using `YOLOv5` and `FastAPI`

Expand Down
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 1acf044

Please sign in to comment.