Can I use Wagtails API to power multiple sites from a single API endpoint?

448 Views Asked by At

In this example wagtail is deployed to cms.example.com and is managing content for foo.example.com and bar.example.com as a headless CMS.

When accessing the Pages API on cms.example.com/api/pages/ only the pages for the current active site (cms.example.com) are returned.

To get the content for the "foo" and "bar" sites cms.example.com/api/ also needs to be available as foo.example.com/api/ and bar.example.com/api/ (e.g. using a proxy).

Is it possible to query the API for pages from other sites without having to go through some proxy?

1

There are 1 best solutions below

3
gasman On

Wagtail's API is a fairly thin layer on top of Django Rest Framework, and you should feel encouraged to customise it or roll your own.

Filtering pages by the current site happens in the PagesAPIEndpoint.get_queryset method, and the simplest way of disabling that behaviour would be to subclass PagesAPIEndpoint to override that method, and register your custom subclass in urls.py in place of the original.