-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (42 loc) · 1.11 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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from config import OriginSettings
from router import auth_router
from functools import lru_cache
from utils.database import DataBase
app = FastAPI(
title='Auth Service',
description='Mere Mehboob Mere sanam',
version='0.1',
contact={
"name": "MFtEK",
},
license_info={
"name": "MIT",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
docs_url="/docs",
redoc_url="/redocs",
root_path="/auth"
)
@lru_cache()
def get_origin():
return OriginSettings()
_origins = get_origin()
origin = [_origins.origin]
app.add_middleware(
CORSMiddleware,
allow_origins=[origin, "http://localhost:3000", "http://localhost:9000"],
allow_credentials=True,
allow_headers=['*', ],
allow_methods=['*', ]
)
app.include_router(auth_router)
@app.on_event("startup")
def init_db():
DataBase()
@app.on_event("shutdown")
def close_db_conn():
print("working")
DataBase().session.commit() # commit everything
DataBase().engine.dispose() # close connection