Skip to content

Commit 256f65b

Browse files
Replace some hardcoded refs to playground.wordpress.net web app (#42)
## Motivation for the change, related issues We are deploying a private Playground instance and want it to reference itself rather than the original public site. In addition, these changes will help folks who also want to self-host. ## Implementation details In general, this PR replaces references to playground.wordpress.net with relative URL references where those references might interfere with Playground platform advances deployed to a private Playground instance. There are a number of references to `https://playground.wordpress.net/plugin-proxy.php`, and I am leaving those alone for now. `plugin-proxy.php` requires a GITHUB_TOKEN environment var, which requires further configuration, and this would be particularly annoying for folks running local Playground servers. For now, let's just keep using the public hosted version of that script and adjust later if required. In other cases, like that of the reference to https://playground.wordpress.net/logger.php, I am leaving the references as-is until there is a benefit to changing them. ## Testing Instructions (or ideally a Blueprint) - CI
1 parent 08d7a8e commit 256f65b

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

packages/playground/client/src/index.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function startPlaygroundWeb({
110110
corsProxy,
111111
shouldInstallWordPress,
112112
}: StartPlaygroundOptions): Promise<PlaygroundClient> {
113-
assertValidRemote(remoteUrl);
113+
assertLikelyCompatibleRemoteOrigin(remoteUrl);
114114
allowStorageAccessByUserActivation(iframe);
115115

116116
remoteUrl = setQueryParams(remoteUrl, {
@@ -192,15 +192,40 @@ function allowStorageAccessByUserActivation(iframe: HTMLIFrameElement) {
192192
}
193193

194194
const officialRemoteOrigin = 'https://playground.wordpress.net';
195-
function assertValidRemote(remoteHtmlUrl: string) {
195+
const validRemoteOrigins = [
196+
officialRemoteOrigin,
197+
// Allow hosting remote from same origin
198+
location.origin,
199+
'http://localhost',
200+
'https://localhost',
201+
'http://127.0.0.1',
202+
'https://127.0.0.1',
203+
];
204+
/**
205+
* Assert that the remote origin is likely compatible with this client library.
206+
*
207+
* Prior to this assertion, there were cases where folks used the client library
208+
* from playground.wordpress.net with other origins and eventually ran into
209+
* compatibility issues when the two sides went out of sync. This way,
210+
* we discourage that practice which is likely to lead to breakage for the
211+
* embedding app.
212+
*
213+
* @param remoteHtmlUrl The URL for remote.html
214+
*/
215+
function assertLikelyCompatibleRemoteOrigin(remoteHtmlUrl: string) {
196216
const url = new URL(remoteHtmlUrl, officialRemoteOrigin);
197-
if (
198-
(url.origin === officialRemoteOrigin || url.hostname === 'localhost') &&
199-
url.pathname !== '/remote.html'
200-
) {
217+
218+
const validRemote =
219+
validRemoteOrigins.includes(url.origin) &&
220+
url.pathname === '/remote.html';
221+
222+
if (!validRemote) {
201223
throw new Error(
202224
`Invalid remote URL: ${url}. ` +
203-
`Expected origin to be ${officialRemoteOrigin}/remote.html.`
225+
'Expected remote URL to have a path of "/remote.html" based ' +
226+
`on one of the following origins:\n ${validRemoteOrigins.join(
227+
'\n'
228+
)}`
204229
);
205230
}
206231
}

packages/playground/remote/remote.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
}
5454
}
5555
</style>
56+
<!-- TODO: Support inserting other origin-trial codes on build, so self-hosted Playground can opt into the trials. -->
5657
<!--
5758
Enable the JSPI origin trial.
5859
Refresh periodically at https://developer.chrome.com/origintrials/#/trials/active

packages/playground/website/public/wordpress.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,12 @@
213213
}
214214

215215
// Redirect to the Playground site with the Blueprint to download and apply the PR
216+
const blueprintSchemaUrl = new URL(
217+
'blueprint-schema.json',
218+
location.href
219+
);
216220
const blueprint = {
217-
$schema:
218-
'https://playground.wordpress.net/blueprint-schema.json',
221+
$schema: blueprintSchemaUrl.href,
219222
landingPage: urlParams.get('url') || '/wp-admin',
220223
login: true,
221224
preferredVersions: {

0 commit comments

Comments
 (0)