-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (37 loc) · 1.1 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
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from starlette.config import Config
from src.database import Database
from src.tasks.router import router
config = Config(".env")
PROJECT_NAME = config("PROJECT_NAME")
ENVIRONMENT = config("ENVIRONMENT")
HOST = config("HOST")
PORT = int(config("PORT"))
SHOW_DOCS_ENVIRONMENT = ("local", "staging", "development")
app_configs = {"title": PROJECT_NAME}
if ENVIRONMENT not in SHOW_DOCS_ENVIRONMENT:
app_configs["openapi_url"] = "" # set url for docs as empty string
app = FastAPI(**app_configs)
app.add_middleware(
CORSMiddleware,
allow_origins=[
"http://localhost",
"http://localhost:8000",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Create Database
Database().create_tables()
@app.get("/")
async def home():
return {
"success": True,
"message": "Welcome to the Another FastAPI Template by Jose Cerrejon!",
}
app.include_router(router)
if __name__ == "__main__":
uvicorn.run("main:app", host=HOST, port=PORT, reload=True)