Skip to content

Saleor Core: the high performance, composable, headless commerce API.

uWSGI use ALLOWED_HOSTS first value as server name instead of hard-coded

Mikail KOCAK23538dad6534
diff --git a/saleor/wsgi/__init__.py b/saleor/wsgi/__init__.py
index 2f94fb0873..5180f5497f 100644
--- a/saleor/wsgi/__init__.py
+++ b/saleor/wsgi/__init__.py
@@ -12,12 +12,19 @@ middleware here, or combine a Django application with an application of another
framework.
"""
import os
-import sys
from django.core.wsgi import get_wsgi_application
+from django.utils.functional import SimpleLazyObject
from saleor.wsgi.health_check import health_check
+
+def get_allowed_host_lazy():
+ from django.conf import settings
+
+ return settings.ALLOWED_HOSTS[0]
+
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saleor.settings")
# This application object is used by any WSGI server configured to use this
@@ -33,11 +40,11 @@ application = health_check(application, "/health/")
application(
{
"REQUEST_METHOD": "GET",
- "SERVER_NAME": "127.0.0.1",
+ "SERVER_NAME": SimpleLazyObject(get_allowed_host_lazy),
"REMOTE_ADDR": "127.0.0.1",
"SERVER_PORT": 80,
"PATH_INFO": "/graphql/",
- "wsgi.input": sys.stdin,
+ "wsgi.input": b"",
},
lambda x, y: None,
)