diff --git a/CHANGELOG.md b/CHANGELOG.md index 366b0fe0d..87d65e40e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,13 @@ Development (master) - Fix checkboxgroup value filtering in the admin to work with arrays of selected values * New Features: - - ... + - Allow placing the map at a path other than the host root. * Upgrade Steps: - - ... + - If you want to take advantage of the new relative paths, you will need to update your templates and CSS files: + - Go through your HTML templates, ensure you're using the `{% static %}` tag to include static files, and update any paths that are not relative to use the `{{route_prefix}}` variable (i.e. `"/places/"` would become `"{{route_prefix}}/places/"}}`). + - Go through your jstemplates and search for href. Update any internal paths to use the new `{{prefix "..."}}` helper. + - Go through your CSS and search for `url(/static/...)`. Ensure that these use relative paths instead (in CSS, `url(...)` paths are relative to the CSS file location). 4.1.0 ----------------------------- diff --git a/doc/CONFIG.md b/doc/CONFIG.md index 6b92d7bd9..ec21e63c9 100644 --- a/doc/CONFIG.md +++ b/doc/CONFIG.md @@ -500,3 +500,14 @@ To change the subject or body of the email that is sent to users, create templat ### Styling See [Customizing the Theme](CUSTOM_THEME.md) + +## Step 4: Deploying your map + +There are a few important environment variables that you can set: + +`SHAREABOUTS_FLAVOR` - The name of the flavor you created in Step 2. This is required. +`SHAREABOUTS_DATASET_ROOT` - The URL to your dataset root. This is required. +`SHAREABOUTS_DATASET_KEY` - The API key for your dataset. This is optional. +`BASE_URL` - If you want to run Shareabouts under a subpath, set this to the path you want to use. For example, if you want to run Shareabouts under `http://example.com/subpath/`, set this to `/subpath/`. **NOTE: unless this is a full URL, it should probably start with a slash, and if it's a path it should probably end in a slash as well.** This is optional. + +For more information see [Deploying Your Map](DEPLOY.md) \ No newline at end of file diff --git a/src/flavors/defaultflavor/config.yml b/src/flavors/defaultflavor/config.yml index f33e0bb45..75b4baeca 100644 --- a/src/flavors/defaultflavor/config.yml +++ b/src/flavors/defaultflavor/config.yml @@ -55,7 +55,7 @@ map: # GeoJSON Layers # ============== - - url: /static/data/philadelphia.geojson + - url: "{{static_url}}/data/philadelphia.geojson" type: json rules: - condition: 'true' @@ -85,7 +85,7 @@ place_types: # Display landmarks as icons when zoomed in icon: - iconUrl: /static/css/images/markers/dot-0d85e9.png + iconUrl: "{{static_url}}/css/images/markers/dot-0d85e9.png" iconSize: [17, 18] iconAnchor: [9, 9] @@ -93,8 +93,8 @@ place_types: # Display landmarks as icons when focused/selected icon: - iconUrl: /static/css/images/markers/marker-0d85e9.png - shadowUrl: /static/css/images/marker-shadow.png + iconUrl: "{{static_url}}/css/images/markers/marker-0d85e9.png" + shadowUrl: "{{static_url}}/css/images/marker-shadow.png" iconSize: [25, 41] shadowSize: [41, 41] iconAnchor: [12, 41] @@ -106,8 +106,8 @@ place_types: # Show parks that are points as icons... icon: - iconUrl: /static/css/images/markers/marker-4bbd45.png - shadowUrl: /static/css/images/marker-shadow.png + iconUrl: "{{static_url}}/css/images/markers/marker-4bbd45.png" + shadowUrl: "{{static_url}}/css/images/marker-shadow.png" iconSize: [25, 41] shadowSize: [41, 41] iconAnchor: [12, 41] @@ -124,7 +124,7 @@ place_types: # Show parks that are points as icons... icon: - iconUrl: /static/css/images/markers/dot-4bbd45.png + iconUrl: "{{static_url}}/css/images/markers/dot-4bbd45.png" iconSize: [17, 18] iconAnchor: [9, 9] @@ -362,11 +362,11 @@ pages: pages: - title: _(Why Shareabouts?) slug: why - url: /static/pages/why.html + url: "{{static_url}}/pages/why.html" - title: _(Features) slug: features - url: /static/pages/features.html + url: "{{static_url}}/pages/features.html" - title: _(Links) pages: diff --git a/src/project/settings.py b/src/project/settings.py index 3b5dc48d4..fe51c236f 100644 --- a/src/project/settings.py +++ b/src/project/settings.py @@ -60,6 +60,13 @@ # If you set this to False, Django will not use timezone-aware datetimes. USE_TZ = True +# Path or URL prefix for all app paths and static files. This is useful if you +# want to run Shareabouts under a subpath, such as `/subpath/`. Note that if the +# `BASE_URL` is set, the site will not work directly through runserver, so you +# should use a reverse proxy in front of it. Thus by default, this is an empty +# string. +BASE_URL = os.environ.get('BASE_URL', '') + # Absolute filesystem path to the directory that will hold user-uploaded files. # Example: "/home/media/media.lawrence.com/media/" MEDIA_ROOT = '' @@ -79,7 +86,7 @@ # URL prefix for static files. # Example: "http://media.lawrence.com/static/" -STATIC_URL = '/static/' +STATIC_URL = BASE_URL + '/static/' COMPRESS_URL = STATIC_URL # Additional locations of static files diff --git a/src/project/urls.py b/src/project/urls.py index ff18360b1..1744a2779 100644 --- a/src/project/urls.py +++ b/src/project/urls.py @@ -3,17 +3,24 @@ from django.contrib import admin from django.views.i18n import set_language +from urllib.parse import urlparse +base_url = urlparse(settings.BASE_URL) +if base_url.path: + base_path = base_url.path.strip('/') + '/' +else: + base_path = '' + admin.autodiscover() urlpatterns = [ - path('choose-language', set_language, name='set_language'), - path('login/', include('sa_login.urls')), - path('admin/', include('sa_admin.urls')), - path('', include('sa_web.urls')), + path(base_path + 'choose-language', set_language, name='set_language'), + path(base_path + 'login/', include('sa_login.urls')), + path(base_path + 'admin/', include('sa_admin.urls')), + path(base_path + '', include('sa_web.urls')), ] if settings.SHAREABOUTS['DATASET_ROOT'].startswith('/'): urlpatterns = [ - path('full-api/', include('sa_api_v2.urls')), + path(base_path + 'full-api/', include('sa_api_v2.urls')), ] + urlpatterns diff --git a/src/sa_admin/templates/sa_admin/base.html b/src/sa_admin/templates/sa_admin/base.html index 69795a380..979af5483 100644 --- a/src/sa_admin/templates/sa_admin/base.html +++ b/src/sa_admin/templates/sa_admin/base.html @@ -67,8 +67,6 @@