Add VITE_CODEX_SELF_HOSTED to define the default url from the self hosted protocol and domain

This commit is contained in:
Arnaud 2025-04-02 15:30:20 +02:00
parent d2be5a6ac2
commit e762e69810
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
2 changed files with 18 additions and 7 deletions

View File

@ -1,8 +1,18 @@
import { Codex } from "@codex-storage/sdk-js"; import { Codex } from "@codex-storage/sdk-js";
import { WebStorage } from "../utils/web-storage"; import { WebStorage } from "../utils/web-storage";
let client: Codex = new Codex(import.meta.env.VITE_CODEX_API_URL); let defaultUrl = import.meta.env.VITE_CODEX_API_URL;
let url: string = import.meta.env.VITE_CODEX_API_URL;
if (import.meta.env.VITE_CODEX_SELF_HOSTED === "1") {
defaultUrl = window.location.href;
if (defaultUrl.endsWith("/")) {
defaultUrl = defaultUrl.slice(0, -1);
}
}
let client: Codex = new Codex(defaultUrl);
let url: string = defaultUrl;
export const CodexSdk = { export const CodexSdk = {
url() { url() {
@ -11,7 +21,7 @@ export const CodexSdk = {
load() { load() {
return WebStorage.get<string>("codex-node-url").then((u) => { return WebStorage.get<string>("codex-node-url").then((u) => {
url = u || import.meta.env.VITE_CODEX_API_URL; url = u || defaultUrl;
client = new Codex(url); client = new Codex(url);
}); });
}, },
@ -24,18 +34,18 @@ export const CodexSdk = {
}, },
debug() { debug() {
return client.debug return client.debug;
}, },
data() { data() {
return client.data return client.data;
}, },
node() { node() {
return client.node return client.node;
}, },
marketplace() { marketplace() {
return client.marketplace return client.marketplace;
}, },
}; };

1
src/vite-env.d.ts vendored
View File

@ -5,6 +5,7 @@ interface ImportMetaEnv {
VITE_CODEX_API_URL: string; VITE_CODEX_API_URL: string;
VITE_GEO_IP_URL: string; VITE_GEO_IP_URL: string;
VITE_DISCORD_LINK: string; VITE_DISCORD_LINK: string;
VITE_CODEX_SELF_HOSTED: string;
} }
interface ImportMeta { interface ImportMeta {