Context
Our users are getting a difficult step to solve when they create their first project with frontity. It is not clear the URL of the WP REST API that should be set in the frontity.settings.js
under the wp-source
package configuration
There are also some community threads regarding this:
The DevRel team will improve the docs but we could also…
Description
Setting the state.source.api
value from the command line to improve the developer experience when creating Frontity projects
Possible solution
When we do npx frontity create my-frontity-project
one of the questions that the CLI could ask could be:
(wpUrl) → What is the URL of the homepage of your Wordpress site (default=https://test.frontity.io/) ?
(isWpCom) → Is it a Wordpress.com site (y/N)?
Use Case 1
-
isWpCom
=no
-
wpUrl
=https://test.frontity.io/
→ state.source.api
= https://test.frontity.io/wp-json/
Use Case 2
-
wpUrl
=https://juanmaguitarblog.wordpress.com/
-
isWpCom
=yes
(in this case this value could be automatically detected and avoid the second question)
state.source.api
= https://wordpress.com/posts/juanmaguitarblog.wordpress.com/wp-json/
Use Case 3
-
wpUrl
=https://instajuegos.home.blog/
-
isWpCom
=yes
(This specific combination of home.blog
+ isWpCom=yes
will result in a wordpress.com subdomain format of REST API)
state.source.api
= https://public-api.wordpress.com/wp/v2/sites/instajuegos.home.blog/posts/
Use Case 4
-
wpUrl
=https://mycoolwpsite.com
-
isWpCom
=yes
(Paid plan w/ custom domain: Personal, Business…)
state.source.api
= https://mycoolwpsite.com/wp-json/
Use Case 5
-
wpUrl
=https://mycoolwpsite.wpcomstaging.com
-
isWpCom
=yes
(Business plan w/ plugins installed w/o custom domain)
state.source.api
= https://mycoolwpsite.wpcomstaging.com/wp-json/
Use Case 6
-
wpUrl
=https://localhost:4000
-
isWpCom
=no
state.source.api
= http://localhost:4000/wp-json