aboutsummaryrefslogtreecommitdiffstats
path: root/backend/__init__.py
blob: 7b4cb4d7c32da3dbf88fb66ddccb6229004d4a19 (plain) (blame)
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
import os

from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.middleware.cors import CORSMiddleware

from backend.authentication import JWTAuthenticationBackend
from backend.route_manager import create_route_map
from backend.middleware import DatabaseMiddleware

middleware = [
    Middleware(
        CORSMiddleware,
        allow_origins=[
            os.getenv("ALLOWED_URL", "https://forms.pythondiscord.com"),
        ],
        allow_headers=[
            "Authorization",
            "Content-Type"
        ],
        allow_methods=["*"]
    ),
    Middleware(DatabaseMiddleware),
    Middleware(AuthenticationMiddleware, backend=JWTAuthenticationBackend())
]

app = Starlette(routes=create_route_map(), middleware=middleware)