|
1 | | -""" |
2 | | -Django settings for backend project. |
3 | | -
|
4 | | -Generated by 'django-admin startproject' using Django 5.0.6. |
5 | | -
|
6 | | -For more information on this file, see |
7 | | -https://docs.djangoproject.com/en/5.0/topics/settings/ |
8 | | -
|
9 | | -For the full list of settings and their values, see |
10 | | -https://docs.djangoproject.com/en/5.0/ref/settings/ |
| 1 | +"""Django settings for the CTJ backend project. |
| 2 | +
|
| 3 | +Settings are read from environment variables via `python-decouple`'s |
| 4 | +`config()` function. Required vars (no default - server fails to |
| 5 | +start if missing): `SECRET_KEY`, `SQL_ENGINE`, `SQL_DATABASE`, |
| 6 | +`SQL_USER`, `SQL_PASSWORD`, `SQL_HOST`, `SQL_PORT`. Optional vars |
| 7 | +with defaults are inline below. Per |
| 8 | +`project_envvars_owned_by_devops`, CTJ engineering declares the |
| 9 | +vars; devops populates the values per environment (incubator |
| 10 | +repo). |
| 11 | +
|
| 12 | +Notable choices: |
| 13 | +- `AUTH_USER_MODEL = "ctj_api.CustomUser"` (subclasses |
| 14 | + `AbstractUser` rather than extending the default User). |
| 15 | +- `daphne` is first in `INSTALLED_APPS` so Django's `runserver` and |
| 16 | + the production server both route through ASGI - see |
| 17 | + `backend.asgi`. |
| 18 | +- `whitenoise` serves static files; the `immutable_file_test` |
| 19 | + function below identifies hashed asset filenames so they can be |
| 20 | + served with long-cache headers. |
| 21 | +- HSTS controls are env-driven; defaults are off so dev/stage stay |
| 22 | + unaffected. Production is expected to set `HSTS_ENABLED=True` and |
| 23 | + the three `*_SECURE`/`SECURE_*` flags below. |
| 24 | +
|
| 25 | +A few config remnants here are dead post-rewrite (template dir |
| 26 | +references to a no-longer-existent `frontend_dist`, plus a |
| 27 | +whitenoise storage workaround). See `scratch/bugs.md` (BUG-007 and |
| 28 | +BUG-010) for the full bug list. |
| 29 | +
|
| 30 | +For Django settings reference: |
| 31 | +https://docs.djangoproject.com/en/6.0/ref/settings/ |
11 | 32 | """ |
12 | 33 |
|
13 | 34 | import re |
|
167 | 188 | # Whitenoise settings |
168 | 189 | # http://whitenoise.evans.io/en/stable/django.html#WHITENOISE_IMMUTABLE_FILE_TEST |
169 | 190 | def immutable_file_test(path, url): |
170 | | - # Match vite (rollup)-generated hashes, à la, `some_file-CSliV9zW.js` |
| 191 | + """Identify static files with hashed names for whitenoise's immutable-cache headers. |
| 192 | +
|
| 193 | + Matches filenames where the segment immediately before the |
| 194 | + extension looks like a content hash (8-12 alphanumeric chars, |
| 195 | + separator preceded by `.` or `-`). Examples that match: |
| 196 | + `app-CSliV9zW.js`, `chunk.abc12345.css`. |
| 197 | +
|
| 198 | + Note: the original regex was tuned for Vite/rollup-style hashes |
| 199 | + (the dropped pre-rewrite frontend). Whether it correctly matches |
| 200 | + Next.js/webpack hashes depends on the chunk-naming output of the |
| 201 | + current build - and post-rewrite the backend doesn't serve the |
| 202 | + frontend's static files anyway. See BUG-008 in scratch/bugs.md. |
| 203 | + """ |
171 | 204 | return re.match(r"^.+[.-][0-9a-zA-Z_-]{8,12}\..+$", url) |
172 | 205 |
|
173 | 206 |
|
|
0 commit comments