UNPKG

@coursebuilder/core

Version:

Core package for Course Builder

55 lines (53 loc) 1.81 kB
import { logger } from "./chunk-B73XG2UO.js"; import { __name } from "./chunk-VLQXSCFN.js"; // src/lib/utils/env.ts function setEnvDefaults(envObject, config) { try { const url = envObject.COURSEBUILDER_URL; if (url && !config.basePath) config.basePath = new URL(url).pathname; } catch { } finally { config.basePath ?? (config.basePath = `/coursebuilder`); } config.providers = config.providers.map((p) => { const finalProvider = typeof p === "function" ? p({}) : p; const ID = finalProvider.id.toUpperCase(); if (finalProvider.type === "transcription") { finalProvider.apiKey ?? (finalProvider.apiKey = envObject[`COURSEBUILDER_${ID}_API_KEY`]); } return finalProvider; }); } __name(setEnvDefaults, "setEnvDefaults"); function createActionURL(action, protocol, headers, envObject, basePath) { let envUrl = envObject.COURSEBUILDER_URL; let url; if (envUrl) { url = new URL(envUrl); if (basePath && basePath !== "/" && url.pathname !== "/") { logger.debug(url.pathname === basePath ? "env-url-basepath-redundant" : "env-url-basepath-mismatch"); url.pathname = "/"; } } else { const detectedHost = headers.get("x-forwarded-host") ?? headers.get("host"); const detectedProtocol = headers.get("x-forwarded-proto") ?? protocol ?? "https"; url = new URL(`${detectedProtocol}://${detectedHost}`); } const sanitizedUrl = url.toString().replace(/\/$/, ""); if (basePath) { const sanitizedBasePath = basePath?.replace(/(^\/|\/$)/g, "") ?? ""; return new URL(`${sanitizedUrl}/${sanitizedBasePath}/${action}`); } return new URL(`${sanitizedUrl}/${action}`); } __name(createActionURL, "createActionURL"); export { setEnvDefaults, createActionURL }; //# sourceMappingURL=chunk-4JVUWPE2.js.map