Skip to content

Commit 43c19c8

Browse files
committed
fix base href
1 parent b8dd85e commit 43c19c8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/editor/src/config/security.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,15 @@ export function getFrameDomain() {
5555
// TODO: now cookies / localstorage are still shared across notebooks. Should we use a unique subdomain per user or notebook?
5656
return "code.typescriptrepl.com";
5757
}
58+
59+
export function getMainDomainFromIframe() {
60+
if (ENVIRONMENT === "DEV") {
61+
const port = window.location.host.match(/^127\.0\.0\.1:(\d+)$/)![1];
62+
return "localhost:" + port;
63+
}
64+
65+
if (ENVIRONMENT === "STAGING") {
66+
return window.location.hostname;
67+
}
68+
return "notebooks.typecell.org";
69+
}

packages/editor/src/index.iframe.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import React from "react";
33
import ReactDOM from "react-dom";
44
// eslint-disable-next-line @typescript-eslint/no-unused-vars
55
import * as reo from "react-error-overlay";
6-
import { validateFrameDomain } from "./config/security";
6+
import {
7+
getMainDomainFromIframe,
8+
validateFrameDomain,
9+
} from "./config/security";
710
import "./iframe.css";
811
import Frame from "./runtime/executor/executionHosts/sandboxed/iframesandbox/Frame";
912

@@ -20,6 +23,7 @@ console.log("Loading iframe", window.location.href);
2023

2124
// make sure links open in new window instead of iframe
2225
const base = document.createElement("base");
26+
base.setAttribute("href", "//" + getMainDomainFromIframe());
2327
base.setAttribute("target", "_blank");
2428
document.head.appendChild(base);
2529

0 commit comments

Comments
 (0)