From 395ced802eade879e21ce83d4d2ed8e5157bf274 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Mon, 4 Aug 2025 13:46:36 +0000 Subject: [PATCH 1/2] add support for github codespaces (but currently does not work, because github seems to have a bug where the other iframes with the other ports return the site from the main port) --- backend/instance_url.ts | 5 +++++ sim/webxdc.ts | 3 +++ 2 files changed, 8 insertions(+) diff --git a/backend/instance_url.ts b/backend/instance_url.ts index 50e81ca..5223487 100644 --- a/backend/instance_url.ts +++ b/backend/instance_url.ts @@ -1,4 +1,5 @@ import { isWebContainer, HostURL } from "@webcontainer/env"; +import { env } from "process"; export function getInstanceUrl(port: number) { if (isWebContainer()) { @@ -6,5 +7,9 @@ export function getInstanceUrl(port: number) { // This is why we need to convert it here. return HostURL.parse(`https://localhost:${port}`).href; } + if (env["CODESPACE_NAME"]) { + return `${env["CODESPACE_NAME"]}-${port}.app.github.dev` + } + return `http://localhost:${port}`; } diff --git a/sim/webxdc.ts b/sim/webxdc.ts index a8d8b02..18d6d57 100644 --- a/sim/webxdc.ts +++ b/sim/webxdc.ts @@ -97,6 +97,9 @@ export class DevServerTransport implements Transport { /--(\d+)--/.exec(document.location.href)?.[1] || "error in webxdc simulator" ); + } else if (location.host.endsWith(".app.github.dev")) { + return /-(\d+)\.app\.github\.dev/.exec(document.location.href)?.[1] || + "error in webxdc simulator" } else { return document.location.port; } From 76e878d625f1232b0b1b92bfe40ec4f464b0b6f7 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Mon, 4 Aug 2025 13:48:39 +0000 Subject: [PATCH 2/2] fix fmt --- backend/instance_url.ts | 2 +- sim/webxdc.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/instance_url.ts b/backend/instance_url.ts index 5223487..b453028 100644 --- a/backend/instance_url.ts +++ b/backend/instance_url.ts @@ -8,7 +8,7 @@ export function getInstanceUrl(port: number) { return HostURL.parse(`https://localhost:${port}`).href; } if (env["CODESPACE_NAME"]) { - return `${env["CODESPACE_NAME"]}-${port}.app.github.dev` + return `${env["CODESPACE_NAME"]}-${port}.app.github.dev`; } return `http://localhost:${port}`; diff --git a/sim/webxdc.ts b/sim/webxdc.ts index 18d6d57..55678fb 100644 --- a/sim/webxdc.ts +++ b/sim/webxdc.ts @@ -98,8 +98,10 @@ export class DevServerTransport implements Transport { "error in webxdc simulator" ); } else if (location.host.endsWith(".app.github.dev")) { - return /-(\d+)\.app\.github\.dev/.exec(document.location.href)?.[1] || + return ( + /-(\d+)\.app\.github\.dev/.exec(document.location.href)?.[1] || "error in webxdc simulator" + ); } else { return document.location.port; }