diff --git a/pyproject.toml b/pyproject.toml index 1393cbe..5278bcd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "Add your description here" readme = "README.md" requires-python = ">=3.13" dependencies = [ + "django-cors-headers>=4.7.0", "django-rest-framework>=0.1.0", "django>=5.1.7", "drf-spectacular>=0.28.0", diff --git a/src/ledger/settings.py b/src/ledger/settings.py index ca99493..fd61635 100644 --- a/src/ledger/settings.py +++ b/src/ledger/settings.py @@ -26,12 +26,15 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = bool(os.environ.get("DJANGO_DEBUG", default="1")) -ALLOWED_HOSTS = ["*"] +ALLOWED_HOSTS = ["*"] if DEBUG else ["ledger.unitystation.org"] # CSRF CSRF_TRUSTED_ORIGINS = ['https://ledger.unitystation.org'] -CORS_ORIGIN_ALLOW_ALL = DEBUG -CORS_ALLOWED_ORIGINS = ['https://ledger.unitystation.org'] + +# CORS +CORS_ALLOW_ALL_ORIGINS = True +CORS_ALLOW_METHODS = ["GET", "HEAD", "OPTIONS"] + SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # Application definition @@ -44,6 +47,7 @@ 'django.contrib.messages', 'whitenoise.runserver_nostatic', 'django.contrib.staticfiles', + 'corsheaders', 'rest_framework', 'transactions', 'drf_spectacular' @@ -51,6 +55,7 @@ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', diff --git a/uv.lock b/uv.lock index ad554b2..c90c5a5 100644 --- a/uv.lock +++ b/uv.lock @@ -33,6 +33,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ba/0f/7e042df3d462d39ae01b27a09ee76653692442bc3701fbfa6cb38e12889d/Django-5.1.7-py3-none-any.whl", hash = "sha256:1323617cb624add820cb9611cdcc788312d250824f92ca6048fda8625514af2b", size = 8276912 }, ] +[[package]] +name = "django-cors-headers" +version = "4.7.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "asgiref" }, + { name = "django" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/93/6c/16f6cb6064c63074fd5b2bd494eb319afd846236d9c1a6c765946df2c289/django_cors_headers-4.7.0.tar.gz", hash = "sha256:6fdf31bf9c6d6448ba09ef57157db2268d515d94fc5c89a0a1028e1fc03ee52b", size = 21037 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/a2/7bcfff86314bd9dd698180e31ba00604001606efb518a06cca6833a54285/django_cors_headers-4.7.0-py3-none-any.whl", hash = "sha256:f1c125dcd58479fe7a67fe2499c16ee38b81b397463cf025f0e2c42937421070", size = 12794 }, +] + [[package]] name = "django-rest-framework" version = "0.1.0" @@ -125,6 +138,7 @@ version = "0.1.0" source = { virtual = "." } dependencies = [ { name = "django" }, + { name = "django-cors-headers" }, { name = "django-rest-framework" }, { name = "drf-spectacular" }, { name = "gunicorn" }, @@ -136,6 +150,7 @@ dependencies = [ [package.metadata] requires-dist = [ { name = "django", specifier = ">=5.1.7" }, + { name = "django-cors-headers", specifier = ">=4.7.0" }, { name = "django-rest-framework", specifier = ">=0.1.0" }, { name = "drf-spectacular", specifier = ">=0.28.0" }, { name = "gunicorn", specifier = ">=23.0.0" },