faustjs
faustjs copied to clipboard
Feature: Error when NEXT_PUBLIC_WORDPRESS_URL same as headless site URL
Tasks
- [ ] I have signed a Contributor License Agreement (CLA) with WP Engine.
- [ ] If a code change, I have written testing instructions that the whole team & outside contributors can understand.
- [ ] I have written and included a comprehensive changeset to properly document the changes I've made.
Description
This pull request adds a check in order to alert Faust users if they accidentally set the NEXT_PUBLIC_WORDPRESS_URL to the URL of their headless site. The code now makes a request to the FaustWP endpoint and checks if the response indicates that the URL is pointing to a headless site.
Related Issue(s):
Testing
To test these changes, follow these steps:
- In the Faust Plugin Settings, set the Headless URL to match the NEXT_PUBLIC_WORDPRESS_URL.
- Try to run the dev or build commands in your headless site. Observe that it should error with the following message:
Validation Failed: Ensure your NEXT_PUBLIC_WORDPRESS_URL does not match with Headless URL in the Faust WordPress plugin settings
Screenshots
Documentation Changes
Dependant PRs
🦋 Changeset detected
Latest commit: 3fcbcc9c169cb28c696ab4978390eca6081767e8
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 2 packages
| Name | Type |
|---|---|
| @faustwp/cli | Patch |
| @faustwp/wordpress-plugin | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
📦 Next.js Bundle Analysis for @faustwp/getting-started-example
This analysis was generated by the Next.js Bundle Analysis action. 🤖
This PR introduced no changes to the JavaScript bundle! 🙌
Hi @theodesp ! Nice job on this, it's going to be so helpful to folks. ✨
I tested this branch by matching the wp-admin URL to the .env.local URL:
This is the error I received:
Everything seems to be working as expected with that error log! I am a little confused on the warning log's behavior, however. I changed my NEXT_PUBLIC_WORDPRESS_URL to another URL to test changes and noted that the warning prompts an update to Faust's plugin:
I think it should be rare for folks to have a misspelling or an entirely incorrect NEXT_PUBLIC_WORDPRESS_URL, but if they do, this warning might be confusing.
I think it should be rare for folks to have a misspelling or an entirely incorrect NEXT_PUBLIC_WORDPRESS_URL, but if they do, this warning might be confusing.
Actually, if you provide an invalid NEXT_PUBLIC_WORDPRESS_URL then it can't even reach the graphQL endpoint since the NEXT_PUBLIC_WORDPRESS_URL is invalid. Chicken and Egg problem.
Maybe if I can update the Validation Error message to say something about the Headless Site URL:
Validation Failed: Your Faust front-end site URL value is misconfigured. It should not match the `NEXT_PUBLIC_WORDPRESS_URL`
I changed my NEXT_PUBLIC_WORDPRESS_URL to another URL to test changes and noted that the warning prompts an update to Faust's plugin ... I think it should be rare for folks to have a misspelling or an entirely incorrect NEXT_PUBLIC_WORDPRESS_URL, but if they do, this warning might be confusing.
I'm guessing the other site doesn't have this branch checked out for the WP plugin? If so, that would be expected behavior since the /validate_public_wordpress_url does not exist on the older versions of Faust WP.
I changed my NEXT_PUBLIC_WORDPRESS_URL to another URL to test changes and noted that the warning prompts an update to Faust's plugin ... I think it should be rare for folks to have a misspelling or an entirely incorrect NEXT_PUBLIC_WORDPRESS_URL, but if they do, this warning might be confusing.
I'm guessing the other site doesn't have this branch checked out for the WP plugin? If so, that would be expected behavior since the
/validate_public_wordpress_urldoes not exist on the older versions of Faust WP.
This is a good point. This could be a breaking change if users are not using the latest plugin version.
Is there a way we could do this check without a new Rest endpoint?
For example, making a request to ${process.env.NEXT_PUBLIC_WORDPRESS_URL}/graphql` and check the response to see if it returns a valid GraphQL query, and if it does, suggest that they might be using their frontend URL instead of their WordPress URL.
Validation Failed: Your Faust front-end site URL value is misconfigured. It should not match the
NEXT_PUBLIC_WORDPRESS_URL
I don't think this is reasonable enough since the user might setup a graphql endpoint on ${headlessURL}/graphql on their own, so it will be a false flag.
Its also very confusing since if the process.env.NEXT_PUBLIC_WORDPRESS_URL points to an actual WP instance, then a request to ${process.env.NEXT_PUBLIC_WORDPRESS_URL}/graphql will always succeed!
This could be a breaking change if users are not using the latest plugin version.
I do check if the response code is 404 which means that the user hasn't updated their plugin to handle the new endpoint so there shouldn't be a breaking change.
This could be a breaking change if users are not using the latest plugin version.
I do check if the response code is 404 which means that the user hasn't updated their plugin to handle the new endpoint so there shouldn't be a breaking change.
Nice 👍 I missed this at first
FAUST_SECRET_KEY
FAUST_SECRET_KEY is required to perform the validation. I will skip the test if this is not provided since it will fail the previews anyway.