Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect NEXT_PUBLIC_WORDPRESS_URL using wpengine.com TLD and recommend using wpenginepowered.com TLD #1801

Merged
merged 7 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-foxes-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/cli': minor
---

Added: Detect if the `NEXT_PUBLIC_WORDPRESS_URL` is a `wpengine.com` TLD and if so recommend a switch to `wpenginepowered.com`
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion packages/faustwp-cli/src/healthCheck/validateFaustEnvVars.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { getWpSecret } from '../utils/index.js';
import { errorLog, warnLog } from '../stdout/index.js';
import { errorLog, infoLog, warnLog } from '../stdout/index.js';

export function isWPEngineComSubdomain(url: string) {
const regex = /\b\w+\.wpengine\.com\b/;

return regex.test(url);
}

/**
* Validates that the appropriate Faust related environment variables are set.
Expand All @@ -11,6 +17,17 @@ export const validateFaustEnvVars = () => {
process.exit(1);
}

if (isWPEngineComSubdomain(process.env.NEXT_PUBLIC_WORDPRESS_URL)) {
infoLog(`Found NEXT_PUBLIC_WORDPRESS_URL using wpengine.com TLD.`);
infoLog(`It is recommended to use the wpenginepowered.com TLD instead.`);
infoLog(
`Ex: https://example.wpengine.com -> https://example.wpenginepowered.com`,
);
infoLog(
`This will leverage WP Engine's Advanced Network CDN. See: https://wpengine.com/support/network/`,
);
}

if (!getWpSecret()) {
warnLog('Could not find FAUST_SECRET_KEY environment variable.');
warnLog('Some functionality may be limited.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { validateFaustEnvVars } from '../../src/healthCheck/validateFaustEnvVars';
import {
isWPEngineComSubdomain,
validateFaustEnvVars,
} from '../../src/healthCheck/validateFaustEnvVars';
/**
* @jest-environment jsdom
*/
Expand Down Expand Up @@ -50,3 +53,26 @@ describe('healthCheck/validateFaustEnvVars', () => {
expect(mockExit).toBeCalledTimes(0);
});
});

describe('isWPEngineComTLD', () => {
it('matches subdomains on wpengine.com', () => {
expect(isWPEngineComSubdomain('https://my-site.wpengine.com')).toBeTruthy();
expect(
isWPEngineComSubdomain('http://some-site.wpengine.com/graphql'),
).toBeTruthy();
expect(isWPEngineComSubdomain('https://example.wpengine.com')).toBeTruthy();
expect(
isWPEngineComSubdomain('https://some-long-weird-subdomain.wpengine.com'),
);
});

it('does not match urls that are not subdomains of wpengine.com', () => {
expect(isWPEngineComSubdomain('https://example.com')).toBeFalsy();
expect(isWPEngineComSubdomain('https://wpengine.com')).toBeFalsy();
expect(isWPEngineComSubdomain('https://wpengine.com/plans')).toBeFalsy();
expect(isWPEngineComSubdomain('https://my-site.wpengine.co')).toBeFalsy();
expect(
isWPEngineComSubdomain('https://my-site.wpenginepowered.com'),
).toBeFalsy();
});
});
Loading