Description
The WordPress backend URL is only on state.source.api
now, and it may (or may not) contain a prefix, usually /wp-json
.
We have started to see more and more examples of different packages that need to know the WordPress URL, not only to access the REST API, but to other uses. Extracting the WordPress URL from state.source.api
is not trivial.
Examples
-
Replace the URL of a link or a meta
For example, changing links fromhttps://wp.domain.com/my-link
tohttps://www.domain.com/my-link
for the@frontity/head-tags
package. -
Link or use a resource or asset that is stored in WordPress
For example, linking to the RSS feedhttps://wp.domain.com/feed
, sitemaphttps://wp.domain.com/sitemap.xml
or service workerhttps://wp.domain.com/sw.js
. -
Other source packages could have different API urls
If we stick with this approach and a package like@frontity/wpgraphql-source
is released, it will break packages depending onstate.source.api
to get the WordPress URL.
I know we’ve seen more examples of this but I don’t remember them right now
Possible solution
Create a global setting for the backend, similar to state.frontity.url
. Then, get rid of it on @frontity/wp-source
, but keep the options that are relevant to the REST API.
export default {
state: {
frontity: {
url: "https://mars.frontity.org",
title: "Test Frontity Blog",
description: "Useful content for Frontity development",
backend: "https://test.frontity.org",
},
},
packages: [
{
name: "@frontity/wp-source",
state: {
source: {
prefix: "/wp-json", // This will be the default.
prefix: false, // To use `?rest_route=`.
isWpCom: true, // To support the WP.com API.
},
},
},
],
};
This should be a backward-compatible change.
Drawbacks:
I guess there could be more than one backend for a single site.
@dev-team opinions?