-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
93 lines (78 loc) · 2.64 KB
/
app.py
File metadata and controls
93 lines (78 loc) · 2.64 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Most top-level instanciator and runner. Main point of entry for the server code.
"""
import logging.config
from fastapi.openapi.utils import get_openapi
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.trustedhost import TrustedHostMiddleware
from fastapi_route_logger_middleware import RouteLoggerMiddleware
from config.db import close_connection_to_mongo, _is_testing
from config.main import app
from routes.users import router as users_router
from routes.events import router as events_router
from routes.feedback import router as feedback_router
from routes.admin import router as admin_router
from routes.images import router as images_router
from routes.auth import router as auth_router
@app.get("/")
def index():
return {"Hello": "World"}
origins = [
"https://localhost",
"http://localhost",
"http://localhost:3000",
"http://localhost:8000",
"http://localhost:8080",
"http://localhost:8081",
"https://sparkdevteams.github.io",
"https://sparkdevteams.github.io/underline-frontend",
"https://github.io",
"https://sparkdev-underline.herokuapp.com",
]
ALLOWED_HOSTS = [
"https://sparkdev-underline.herokuapp.com",
"https://sparkdevteams.github.io",
"https://sparkdevteams.github.io/underline-frontend",
"https://github.io",
"http://localhost:80800",
"http://localhost:8000",
"http://localhost:8080",
"http://localhost",
"http://localhost",
"localhost",
"http://localtest.me:80800",
"http://localtest.me",
"http://localtest.me",
"localtest.me",
"*",
]
ALLOWED_HEADERS = ["*", "x-requested-with"]
app.add_middleware(CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=ALLOWED_HEADERS)
app.add_middleware(
TrustedHostMiddleware,
allowed_hosts=ALLOWED_HOSTS if not _is_testing() else ["*"],
)
logging.config.fileConfig("./logging.conf")
app.add_middleware(RouteLoggerMiddleware)
def custom_schema():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title="Underline x Sparkdev API",
version="v.1.0",
description="Backend API for 2021 Spring FUTxSparkdev project",
routes=app.routes)
app.openapi_schema = openapi_schema
return app.openapi_schema
app.include_router(users_router)
app.include_router(events_router)
app.include_router(feedback_router)
app.include_router(admin_router)
app.include_router(images_router)
app.include_router(auth_router)
app.add_event_handler("shutdown", close_connection_to_mongo)
app.openapi = custom_schema