Sudipta Nayak
commited on
Commit
·
aeee3ba
1
Parent(s):
39e53c4
settings folder added
Browse files- app/config.py +25 -0
- app/main.py +16 -1
app/config.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
from pydantic import AnyHttpUrl, BaseSettings
|
5 |
+
|
6 |
+
class Settings(BaseSettings):
|
7 |
+
API_V1_STR: str = "/api/v1"
|
8 |
+
|
9 |
+
# Meta
|
10 |
+
|
11 |
+
# BACKEND_CORS_ORIGINS is a comma-separated list of origins
|
12 |
+
# e.g: http://localhost,http://localhost:4200,http://localhost:3000
|
13 |
+
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = [
|
14 |
+
"http://localhost:3000", # type: ignore
|
15 |
+
"http://localhost:8000", # type: ignore
|
16 |
+
"https://localhost:3000", # type: ignore
|
17 |
+
"https://localhost:8000", # type: ignore
|
18 |
+
]
|
19 |
+
|
20 |
+
PROJECT_NAME: str = "Object Detection"
|
21 |
+
|
22 |
+
class Config:
|
23 |
+
case_sensitive = True
|
24 |
+
|
25 |
+
settings = Settings()
|
app/main.py
CHANGED
@@ -4,8 +4,11 @@ from fastapi.templating import Jinja2Templates
|
|
4 |
from pydantic import BaseModel
|
5 |
import subprocess
|
6 |
from pathlib import Path
|
|
|
7 |
|
8 |
-
app = FastAPI(
|
|
|
|
|
9 |
|
10 |
app.mount("/static", FileResponse, name="static")
|
11 |
|
@@ -37,6 +40,18 @@ async def detect_objects(request: Request, item: Item):
|
|
37 |
)
|
38 |
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
# Start app
|
41 |
if __name__ == "__main__":
|
42 |
import uvicorn
|
|
|
4 |
from pydantic import BaseModel
|
5 |
import subprocess
|
6 |
from pathlib import Path
|
7 |
+
from app.config import settings
|
8 |
|
9 |
+
app = FastAPI(
|
10 |
+
title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json"
|
11 |
+
)
|
12 |
|
13 |
app.mount("/static", FileResponse, name="static")
|
14 |
|
|
|
40 |
)
|
41 |
|
42 |
|
43 |
+
|
44 |
+
# Set all CORS enabled origins
|
45 |
+
if settings.BACKEND_CORS_ORIGINS:
|
46 |
+
app.add_middleware(
|
47 |
+
CORSMiddleware,
|
48 |
+
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
|
49 |
+
allow_credentials=True,
|
50 |
+
allow_methods=["*"],
|
51 |
+
allow_headers=["*"],
|
52 |
+
)
|
53 |
+
|
54 |
+
|
55 |
# Start app
|
56 |
if __name__ == "__main__":
|
57 |
import uvicorn
|