Tools for using Wagtail API with JavaScript single page apps
pip install wagtail-spa-integration==3.1.0
This project provides some tools for using Wagtail as an API only CMS that a JS application will consume.
It was designed to work with angular-wagtail - but works without Angular if you provide the client integration.
wagtail-spa-integration
wagtail_spa_integration
to INSTALLED_APPSwagtail_spa_integration.views.SPAExtendedPagesAPIEndpoint
instead of Wagtail's PagesAPIEndpoint.from wagtail_spa_integration.views import RedirectViewSet
PREVIEW_DRAFT_CODE = "anything"
to use the preview feature.The draft code is computed from a sha256 hash of the date + PREVIEW_DRAFT_CODE + the page ID. This results in a expiring unique code per page. However that code does not require authentication. This is helpful for sharing the draft with others and avoids problems with using session authentication over several domains.
If your security use case cannot allow a reused code that is also sent as a query parameter and thus may be logged, you should not use the draft preview feature. It's made under the assumption that the data behind it is not very secretive. If you do require secrecy, you should extend the SPAExtendedPagesAPIEndpoint endpoint and implement your own authentication mechanism. If working across domains, this may require token or JWT authentication.
Wagtail itself can support a base API url and multiple "sites" For example:
This set up would require multiple Wagtail Sites and each Site needs it's own page.
WAGTAILAPI_BASE_URL
must be set in settings.py so that the API shows the correct detail_url
in the API.
If may be useful to explicitly request a sitemap.xml for a specific site. from wagtail_spa_integration.views import sitemap
adds a query parameter site
for this. Use it exactly as you would wagtail's sitemap. Then add a query parameter like example.com/sitemap.xml?site=2
.
Follow instructions on Angular-Wagtail.
Review the angular-wagtail project and reimplement it's logic. Essentially you'll need to make a page router that loads pages from the api and connects wagtail pages to your view layer. For example a wagtail page HomePage would need to be connected to a JS HomePageComponent.
It's not likely that I'll be developing other integrations, but if you make an integration for your favorite JS framework I'd be happy to note it here. Angular happens to be a good fit because we can expect certain resources to be available (Router Module, transfer state, etc).
Create fixtures with ./manage.py dumpdata --natural-foreign --indent 2 -e contenttypes -e auth.permission -e wagtailcore.groupcollectionpermission -e wagtailcore.grouppagepermission -e wagtailimages.rendition -e sessions > data.json
Load fixtures with ./manage.py loaddata data.json
Submit a tag starting with the letter v such as v2.0.0
and CI will automatically publish