-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (38 loc) · 1.51 KB
/
Copy pathmain.py
File metadata and controls
48 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from utils.config import settings
from utils.lifetime import startup
from api.v1.endpoints.health import router as healthCheck_router
from api.v1.endpoints.hello_world import router as hello_world_router
from utils.logger import logger
def configureStatic(_app):
"""serve static content
Configure the static folder within the main.py's folder to serve static files under the /static/ prefix
it automatically loads index.html for directories if such file exist.
"""
_app.mount("/static", StaticFiles(directory=settings.PATHS.BASE_DIR / "static", html=True), name="static")
def getApplication() -> FastAPI:
_app = FastAPI(
title=settings.APP_TITLE,
description=settings.APP_DESCRIPTION,
debug=settings.DEBUG,
lifespan=startup,
)
_app.include_router(healthCheck_router, prefix="/api/v1")
_app.include_router(hello_world_router, prefix="/api/v1")
configureStatic(_app)
_app.add_middleware(
CORSMiddleware,
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
return _app
app = getApplication()
if __name__ == '__main__':
# Use this for debugging purposes only
import uvicorn
logger.info("running from command line")
uvicorn.run(app, host='0.0.0.0', port=8000, log_level='debug')