-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (48 loc) · 1.41 KB
/
main.py
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
49
50
51
52
53
54
55
56
57
58
59
import os.path
import sqlite3
from fastapi.middleware.cors import CORSMiddleware
from fastapi import HTTPException
from fastapi.staticfiles import StaticFiles
from starlette.responses import RedirectResponse
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR
from backend import app
from backend.database.master import create_tables
# Configure CORS settings
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.mount(
"/", StaticFiles(directory="./frontend/dist", html=True)
)
@app.on_event("startup")
async def startup():
"""
Performs startup tasks.
This function is executed when the application starts up. It calls the `create_tables` function
to create necessary database tables.
"""
if os.path.exists(os.path.join("backend", "database", "ekipa.db")):
pass
else:
sqlite3.connect(os.path.join("backend", "database", "ekipa.db"))
await create_tables()
@app.get("/")
async def read_index():
"""
Redirects to the static folder.
Returns:
"""
try:
return RedirectResponse(url="/")
except Exception as error:
raise HTTPException(
status_code=HTTP_500_INTERNAL_SERVER_ERROR, detail="Internal Server Error"
) from error
# Path: main.py
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", reload=True)