1
0
mirror of https://github.com/etesync/server synced 2024-10-31 20:58:54 +00:00

Add trusted host middleware.

This commit is contained in:
Tom Hacohen 2020-12-28 10:57:40 +02:00
parent 38884fead8
commit ad2205e596

View File

@ -1,7 +1,6 @@
import os
from django.core.wsgi import get_wsgi_application
from fastapi.middleware.cors import CORSMiddleware
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "etebase_server.settings")
application = get_wsgi_application()
@ -10,6 +9,8 @@ from django.conf import settings
# Not at the top of the file because we first need to setup django
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.trustedhost import TrustedHostMiddleware
from .exceptions import CustomHttpException
from .authentication import authentication_router
@ -35,6 +36,7 @@ if settings.DEBUG:
app.add_middleware(
CORSMiddleware, allow_origin_regex="https?://.*", allow_credentials=True, allow_methods=["*"], allow_headers=["*"]
)
app.add_middleware(TrustedHostMiddleware, allowed_hosts=settings.ALLOWED_HOSTS)
@app.exception_handler(CustomHttpException)