Skip to content

Commit

Permalink
Support site_root_url placeholder in "default" preview client url
Browse files Browse the repository at this point in the history
  • Loading branch information
jaap3 committed Feb 8, 2021
1 parent e16d107 commit d184f7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ Run migrations:
$ ./manage.py migrate
```

then configure the preview client URL using the `HEADLESS_PREVIEW_CLIENT_URLS` setting.
Then configure the preview client URL using the `HEADLESS_PREVIEW_CLIENT_URLS` setting:

For single site, the configuration should look like:
```python
HEADLESS_PREVIEW_CLIENT_URLS = {
'default': '{site_root_url}/',
}
```

The `{site_root_url}` placeholder is replaced with the `root_url` of the `Site` the preview page belongs to.

If the Wagtail `Site` object isn't configured with the frontend domain it is possible to hardcode an url:

```python
HEADLESS_PREVIEW_CLIENT_URLS = {
Expand Down
7 changes: 5 additions & 2 deletions wagtail_headless_preview/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ def update_page_preview(self, token):
)

def get_client_root_url(self):
site = self.get_site()
try:
return settings.HEADLESS_PREVIEW_CLIENT_URLS[self.get_site().hostname]
return settings.HEADLESS_PREVIEW_CLIENT_URLS[site.hostname]
except (AttributeError, KeyError):
return settings.HEADLESS_PREVIEW_CLIENT_URLS["default"]
return settings.HEADLESS_PREVIEW_CLIENT_URLS["default"].format(
site_root_url=site.root_url
)

@classmethod
def get_content_type_str(cls):
Expand Down

0 comments on commit d184f7d

Please # to comment.