-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
51 lines (35 loc) · 1.18 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
import os
from sqlalchemy.engine import create_engine
if os.getenv('API_ENV') != 'production':
from dotenv import load_dotenv
load_dotenv()
import uvicorn
import sql_app.database as db
import logging
from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
from routers import webhooks, users
logger = logging.getLogger(__name__)
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.on_event("startup")
async def startup() -> None:
SQLALCHEMY_DATABASE_URL = os.getenv('DATABASE_URI')
engine = create_engine(SQLALCHEMY_DATABASE_URL)
db.Base.metadata.create_all(bind=engine)
@app.on_event("shutdown")
async def shutdown():
db.SessionLocal().close()
app.include_router(webhooks.router)
app.include_router(users.router)
@app.get("/")
async def root():
return {"message": "Hello World!"}
@app.get("/liff", response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0"
, port=5000, reload=True
)