-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathmain.py
35 lines (30 loc) · 949 Bytes
/
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.trustedhost import TrustedHostMiddleware
from app.api.api_router import api_router, auth_router
from app.core.config import get_settings
app = FastAPI(
title="minimal fastapi postgres template",
version="6.1.0",
description="https://github.com/rafsaf/minimal-fastapi-postgres-template",
openapi_url="/openapi.json",
docs_url="/",
)
app.include_router(auth_router)
app.include_router(api_router)
# Sets all CORS enabled origins
app.add_middleware(
CORSMiddleware,
allow_origins=[
str(origin).rstrip("/")
for origin in get_settings().security.backend_cors_origins
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Guards against HTTP Host Header attacks
app.add_middleware(
TrustedHostMiddleware,
allowed_hosts=get_settings().security.allowed_hosts,
)