-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (50 loc) · 1.69 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
import logging
import logging.config
import os
import sys
import sentry_sdk
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.integrations.logging import LoggingIntegration
from fastdrewdru import config
from fastdrewdru.views import router as fastdrewdru_router
from helloworld.views import router as helloworld_router
from movies.views import router as movies_router
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)
settings = config.get_settings()
# region: Initialize logs
logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
logger = logging.getLogger(__name__)
sentry_logging = LoggingIntegration(
level=logging.WARNING, # Capture info and above as breadcrumbs
event_level=logging.ERROR, # Send errors as events
)
sentry_sdk.init(
settings.SENTRY_DNS,
traces_sample_rate=settings.SENTRY_TRACES_SAMPLE_RATE,
integrations=[sentry_logging],
)
# endregion
app = FastAPI(
title="drewdru.com",
description="REST API for drewdru.com",
version=settings.version,
)
# region: Initialize middlewares
app.add_middleware(SentryAsgiMiddleware)
app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ORIGIN_WHITELIST,
allow_origin_regex=settings.CORS_ORIGIN_REGEX_WHITELIST,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# endregion
# region: Initialize routers
app.include_router(fastdrewdru_router)
app.include_router(movies_router, prefix="/movies", tags=["movies"])
app.include_router(helloworld_router, prefix="/helloworld", tags=["helloworld"])
# endregion