1
-
2
1
import os
3
2
import sys
4
3
from pathlib import Path
@@ -55,7 +54,8 @@ def require_env_var(env_var: str) -> str:
55
54
SECRET_KEY = require_env_var ('SECRET_KEY' )
56
55
DEBUG = get_env_bool ('DEBUG' , default = False )
57
56
58
- ALLOWED_HOSTS = parse_env_list ("ALLOWED_HOSTS" )
57
+ # ALLOWED_HOSTS = parse_env_list("ALLOWED_HOSTS")
58
+ ALLOWED_HOSTS = ['*' ]
59
59
60
60
# ---------------------------------------------------------
61
61
# Application Definitions
@@ -100,7 +100,7 @@ def require_env_var(env_var: str) -> str:
100
100
# Middleware
101
101
# ---------------------------------------------------------
102
102
MIDDLEWARE = [
103
- 'corsheaders.middleware.CorsMiddleware' ,
103
+ 'corsheaders.middleware.CorsMiddleware' , # Must be first
104
104
'django.middleware.security.SecurityMiddleware' ,
105
105
'whitenoise.middleware.WhiteNoiseMiddleware' ,
106
106
'django.contrib.sessions.middleware.SessionMiddleware' ,
@@ -114,11 +114,75 @@ def require_env_var(env_var: str) -> str:
114
114
# ---------------------------------------------------------
115
115
# CORS and CSRF Configuration
116
116
# ---------------------------------------------------------
117
- CORS_ORIGIN_ALLOW_ALL = False
118
- CORS_ALLOWED_ORIGINS = parse_env_list ("CORS_ALLOWED_ORIGINS" )
119
- CORS_ORIGIN_REGEX_WHITELIST = parse_env_list ("CORS_ORIGIN_REGEX_WHITELIST" )
120
- CSRF_TRUSTED_ORIGINS = parse_env_list ("CSRF_TRUSTED_ORIGINS" )
121
-
117
+ if DEBUG :
118
+ # Allow all CORS origins during development
119
+ CORS_ORIGIN_ALLOW_ALL = True
120
+ CORS_ALLOWED_ORIGINS = []
121
+ CORS_ORIGIN_REGEX_WHITELIST = []
122
+
123
+ # Allow all CSRF origins during development
124
+ CSRF_TRUSTED_ORIGINS = [
125
+ "https://website-trigger-3-website-preview-w7kzhvlewq-ew.a.run.app" ,
126
+ ]
127
+
128
+ # Optionally, you can add more relaxed settings
129
+ # For example, allow specific subdomains or ports if needed
130
+ else :
131
+ # Restrict CORS origins in production
132
+ CORS_ORIGIN_ALLOW_ALL = False
133
+ CORS_ALLOWED_ORIGINS = [
134
+ "https://staging-dot-airqo-frontend.appspot.com" ,
135
+ "https://staging.airqo.net" ,
136
+ "https://airqo.net" ,
137
+ "https://airqo.africa" ,
138
+ "https://airqo.org" ,
139
+ "https://airqo.mak.ac.ug" ,
140
+ "http://127.0.0.1:8000" ,
141
+ "http://localhost:3000" ,
142
+ "https://staging-platform.airqo.net" ,
143
+ "https://staging-analytics.airqo.net" ,
144
+ "https://analytics.airqo.net" ,
145
+ "https://platform.airqo.net" ,
146
+ ]
147
+ CORS_ORIGIN_REGEX_WHITELIST = [
148
+ # Matches subdomains under airqo.net, airqo.africa, airqo.org, airqo.io
149
+ r"^https://[a-zA-Z0-9_\-]+\.airqo\.(net|africa|org|io)$" ,
150
+ # Matches airqo.africa, airqo.org, and airqo.mak.ac.ug
151
+ r"^https://airqo\.(africa|org|mak\.ac\.ug)$" ,
152
+ # Matches staging-dot-airqo-frontend.appspot.com
153
+ r"^https://staging-dot-airqo-frontend\.appspot\.com$" ,
154
+ r"^https://staging-platform\.airqo\.net$" , # Matches staging-platform.airqo.net
155
+ # Matches staging-analytics.airqo.net
156
+ r"^https://staging-analytics\.airqo\.net$" ,
157
+ r"^https://analytics\.airqo\.net$" , # Matches analytics.airqo.net
158
+ r"^https://platform\.airqo\.net$" , # Matches platform.airqo.net
159
+ # Matches any subpath under https://platform.airqo.net/website/admin
160
+ r"^https://platform\.airqo\.net/website/admin.*$" ,
161
+ # Matches any subpath under https://staging-platform.airqo.net/website/admin
162
+ r"^https://staging-platform\.airqo\.net/website/admin.*$" ,
163
+ ]
164
+
165
+ # Trust specific origins for CSRF protection in production
166
+ # CSRF_TRUSTED_ORIGINS = parse_env_list("CSRF_TRUSTED_ORIGINS")
167
+ CSRF_TRUSTED_ORIGINS = [
168
+ "https://staging-dot-airqo-frontend.appspot.com" ,
169
+ "https://staging.airqo.net" ,
170
+ "https://airqo.net" ,
171
+ "https://airqo.africa" ,
172
+ "https://airqo.org" ,
173
+ "https://airqo.mak.ac.ug" ,
174
+ "http://127.0.0.1:8000" ,
175
+ "http://localhost:3000" ,
176
+ "https://*.cloudshell.dev" ,
177
+ "https://staging-platform.airqo.net" ,
178
+ "https://staging-analytics.airqo.net" ,
179
+ "https://analytics.airqo.net" ,
180
+ "https://platform.airqo.net" ,
181
+ "https://website-trigger-3-website-preview-w7kzhvlewq-ew.a.run.app" ,
182
+ ]
183
+
184
+
185
+ # Security settings
122
186
CSRF_COOKIE_SECURE = not DEBUG
123
187
SESSION_COOKIE_SECURE = not DEBUG
124
188
@@ -190,7 +254,6 @@ def require_env_var(env_var: str) -> str:
190
254
STATICFILES_DIRS = [BASE_DIR / 'static' ]
191
255
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
192
256
193
-
194
257
if DEBUG :
195
258
# Local file storage for development
196
259
MEDIA_URL = '/media/'
@@ -231,7 +294,11 @@ def require_env_var(env_var: str) -> str:
231
294
# ---------------------------------------------------------
232
295
# File Upload Limits
233
296
# ---------------------------------------------------------
234
- MAX_UPLOAD_SIZE = 10 * 1024 * 1024 # 10MB
297
+ # Define a constant for maximum upload size
298
+ MAX_UPLOAD_SIZE_MB = 10 # Maximum upload size in MB
299
+ MAX_UPLOAD_SIZE = MAX_UPLOAD_SIZE_MB * 1024 * 1024 # Convert to bytes
300
+
301
+ # Apply the maximum upload size to Django settings
235
302
DATA_UPLOAD_MAX_MEMORY_SIZE = MAX_UPLOAD_SIZE
236
303
FILE_UPLOAD_MAX_MEMORY_SIZE = MAX_UPLOAD_SIZE
237
304
@@ -254,6 +321,9 @@ def require_env_var(env_var: str) -> str:
254
321
},
255
322
}
256
323
324
+ # ---------------------------------------------------------
325
+ # Quill Editor Configuration
326
+ # ---------------------------------------------------------
257
327
QUILL_CONFIGS = {
258
328
'default' : {
259
329
'theme' : 'snow' ,
0 commit comments