Skip to content

Commit

Permalink
fix(playground): use localhost if on localhost (#12227)
Browse files Browse the repository at this point in the history
When running on localhost use localhost for playground urls.
  • Loading branch information
fiji-flo authored Dec 5, 2024
1 parent 4cc84ca commit e11f62e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
12 changes: 7 additions & 5 deletions client/src/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ export default function Playground() {

// We're using a random subdomain for origin isolation.
const url = new URL(
`${window.location.protocol}//${
PLAYGROUND_BASE_HOST.startsWith("localhost")
? ""
: `${subdomain.current}.`
}${PLAYGROUND_BASE_HOST}`
window.location.hostname.endsWith("localhost")
? window.location.origin
: `${window.location.protocol}//${
PLAYGROUND_BASE_HOST.startsWith("localhost")
? ""
: `${subdomain.current}.`
}${PLAYGROUND_BASE_HOST}`
);
setVConsole([]);
url.searchParams.set("state", state);
Expand Down
12 changes: 7 additions & 5 deletions client/src/playground/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ export async function initPlayIframe(
JSON.stringify(editorContent)
);
const path = iframe.getAttribute("data-live-path");
const host = PLAYGROUND_BASE_HOST.startsWith("localhost")
? PLAYGROUND_BASE_HOST
: `${hash}.${PLAYGROUND_BASE_HOST}`;
const url = new URL(
`${path || ""}${path?.endsWith("/") ? "" : "/"}runner.html`,
window.location.origin
);
url.port = "";
url.host = host;
if (!window.location.hostname.endsWith("localhost")) {
const host = PLAYGROUND_BASE_HOST.startsWith("localhost")
? PLAYGROUND_BASE_HOST
: `${hash}.${PLAYGROUND_BASE_HOST}`;
url.port = "";
url.host = host;
}
url.search = "";
url.searchParams.set("state", state);
iframe.src = url.href;
Expand Down
2 changes: 2 additions & 0 deletions client/src/setupProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function config(app) {
app.use(`**/*.(gif|jpeg|jpg|mp3|mp4|ogg|png|svg|webm|webp|woff2)`, proxy);
// All those root-level images like /favicon-48x48.png
app.use("/*.(png|webp|gif|jpe?g|svg)", proxy);
// Proxy play runner
app.use("/**/runner.html", proxy);
}

export default config;

0 comments on commit e11f62e

Please sign in to comment.