Changeset - 5fa226284bcb
[Not reviewed]
1 7 0
Ben Sturmfels (bsturmfels) - 1 month ago 2024-03-20 03:54:54
ben@sturm.com.au
Delegate management of canonical URLs to Apache

This middleware is mostly redundant:

* redirecting to canonical URLs can be done more simply in Apache
* appending a forward slash is a default in CommonMiddleware now
* we're no longer using Squid cache

May need to update Apache to strip/redirect trailing "index.html".
8 files changed with 4 insertions and 85 deletions:
0 comments (0 inline, 0 general)
TODO.md
Show inline comments
 
# To-do
 

	
 
* remove `ForceCanonicalHostnameMiddleware` by ensuring canonical redirect and HTTPS redirect is done by Apache
 
* ask Denver about why so many license files
 
* serve a 400 in Apache for a hostname we don't explicitly support
 
* use `<detail>` elements for supporter page hidden sections, rather than complex jQuery - or consider Alpine.js
 
* replace `internalNavigate` with inline flexbox layout
...
 
@@ -9,6 +9,7 @@
 

	
 
# Done
 

	
 
* remove `ForceCanonicalHostnameMiddleware` by ensuring canonical redirect and HTTPS redirect is done by Apache
 
* standardise settings to replace `settings.py` and `djangocommonsettings.py`
 
  with `settings/prod.py` and move `SECRET_KEY` to an environment variable
 
* migrate to Django 4.2 LTS
conservancy/blog/views.py
Show inline comments
...
 
@@ -114,11 +114,8 @@ def query(request):
 

	
 
def relative_redirect(request, path):
 
    from django import http
 
    from django.conf import settings
 

	
 
    host = request.get_host()
 
    if settings.FORCE_CANONICAL_HOSTNAME:
 
        host = settings.FORCE_CANONICAL_HOSTNAME
 

	
 
    url = "{}://{}{}".format(request.is_secure() and 'https' or 'http', host, path)
 
    return http.HttpResponseRedirect(url)
conservancy/local_context_processors.py
Show inline comments
 
from datetime import datetime as DateTime
 

	
 
from django.conf import settings
 

	
 
from .fundgoal.models import FundraisingGoal
 

	
 
SITE_FUNDGOAL = 'cy2023-end-year-match'
...
 
@@ -19,10 +17,5 @@ def sitefundraiser(request):
 
        'sitefundgoal': fundgoal_lookup(SITE_FUNDGOAL),
 
    }
 

	
 
if settings.FORCE_CANONICAL_HOSTNAME:
 
    _HOST_URL_VAR = {'host_url': 'https://' + settings.FORCE_CANONICAL_HOSTNAME}
 
    def host_url(request):
 
        return _HOST_URL_VAR
 
else:
 
    def host_url(request):
 
        return {'host_url': request.build_absolute_uri('/').rstrip('/')}
 
def host_url(request):
 
    return {'host_url': request.build_absolute_uri('/').rstrip('/')}
conservancy/middleware.py
Show inline comments
 
deleted file
conservancy/podjango/views.py
Show inline comments
...
 
@@ -105,11 +105,8 @@ def query(request):
 

	
 
def relative_redirect(request, path):
 
    from django import http
 
    from django.conf import settings
 

	
 
    host = http.get_host(request)
 
    if settings.FORCE_CANONICAL_HOSTNAME:
 
        host = settings.FORCE_CANONICAL_HOSTNAME
 

	
 
    url = "%s://%s%s" % (request.is_secure() and 'https' or 'http', host, path)
 
    return http.HttpResponseRedirect(url)
conservancy/settings/base.py
Show inline comments
...
 
@@ -22,10 +22,6 @@ from pathlib import Path
 
SITE_ID = 2
 
ROOT_URLCONF = 'conservancy.urls'
 

	
 
REDIRECT_TABLE = {
 
    'www.sf-conservancy.org': 'sfconservancy.org',
 
}
 

	
 
LOGGING = {
 
    'version': 1,
 
    'disable_existing_loggers': False,
...
 
@@ -136,7 +132,6 @@ MIDDLEWARE = [
 
    'django.contrib.sessions.middleware.SessionMiddleware',
 
    'django.contrib.auth.middleware.AuthenticationMiddleware',
 
    'django.contrib.messages.middleware.MessageMiddleware',
 
    'conservancy.middleware.ForceCanonicalHostnameMiddleware',
 
]
 

	
 
USETHESOURCE = {
conservancy/settings/dev.py
Show inline comments
...
 
@@ -3,8 +3,6 @@ from .base import *
 
DEBUG = True
 
ALLOWED_HOSTS = ['*']
 

	
 
FORCE_CANONICAL_HOSTNAME = False
 

	
 
DATABASES = {
 
    'default': {
 
        'NAME': 'conservancy-website.sqlite3',
conservancy/settings/prod.py
Show inline comments
...
 
@@ -7,8 +7,6 @@ from .base import *
 
DEBUG = False
 
ALLOWED_HOSTS = ['www.sfconservancy.org', 'sfconservancy.org']
 

	
 
FORCE_CANONICAL_HOSTNAME = 'sfconservancy.org'
 

	
 
ADMINS = [
 
    ('Bradley M. Kuhn', 'sysadmin@sfconservancy.org'),
 
    ('Ben Sturmfels', 'sysadmin+conservancy@sturm.com.au'),
0 comments (0 inline, 0 general)