-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
74 lines (56 loc) · 1.74 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import logging
import logging
import uvicorn
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
import sentry_sdk
from fastapi.middleware.cors import CORSMiddleware
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from starlette.responses import RedirectResponse
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from database.db import create_db_and_tables
from route.router import api_router
from config.config import SENTRY_DSN, SENTRY_ENV, SENTRY_TRACES_SAMPLE_RATE
sentry_sdk.init(
dsn=SENTRY_DSN,
environment=SENTRY_ENV,
traces_sample_rate=SENTRY_TRACES_SAMPLE_RATE,
# integrations=[
# RedisIntegration(),
# ],
)
app = FastAPI()
origins = [
"http://dryrain39.github.io",
"https://dryrain39.github.io",
"http://kpc",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
try:
app.add_middleware(SentryAsgiMiddleware)
except Exception as e:
logging.error("SENTRY INIT FAILED.", exc_info=True)
pass
# 라우터 추가
app.include_router(api_router)
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/7qy38tiejfkdnojiwgu9eyhijdfk")
async def server_checker():
return {"message": "Hello World"}
@app.on_event("startup")
async def on_startup():
# Not needed if you setup a migration system like Alembic
await create_db_and_tables()
@app.get("/")
async def root():
return RedirectResponse(url='/static/index.html')
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8001, reload=True, log_level="debug", debug=True, proxy_headers=True,
forwarded_allow_ips='*')