Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): add server URL routing helpers

Richie McIlroya4b6774cf96d
diff --git a/apps/desktop/src/utils/server-url-routing.ts b/apps/desktop/src/utils/server-url-routing.ts
new file mode 100644
index 000000000..3e8f185df
--- /dev/null
+++ b/apps/desktop/src/utils/server-url-routing.ts
@@ -0,0 +1,30 @@
+export function hasSameOrigin(left: string, right: string) {
+ return new URL(left).origin === new URL(right).origin;
+}
+
+export function shouldUseLocalServerSessionForUrl(
+ configuredServerUrl: string,
+ packagedServerUrl: string,
+ isDev: boolean,
+) {
+ if (isDev) return true;
+
+ return !hasSameOrigin(configuredServerUrl, packagedServerUrl);
+}
+
+export function resolveServerRequestPath(
+ path: string,
+ configuredServerUrl: string,
+ packagedServerUrl: string,
+) {
+ if (hasSameOrigin(configuredServerUrl, packagedServerUrl)) return path;
+
+ const packagedOrigin = new URL(packagedServerUrl).origin;
+ const url = new URL(path, packagedServerUrl);
+ if (url.origin !== packagedOrigin) return path;
+
+ return new URL(
+ `${url.pathname}${url.search}${url.hash}`,
+ configuredServerUrl,
+ ).toString();
+}