one
Version:
One is a new React Framework that makes Vite serve both native and web.
46 lines (45 loc) • 1.56 kB
JavaScript
const protocolWarningString = `{ plugins: [["router", { origin: "...<URL>..." }]] }`;
function memoize(fn) {
const cache = {};
return (...args) => {
const key = JSON.stringify(args);
if (cache[key]) {
return cache[key];
}
const result = fn(...args);
cache[key] = result;
return result;
};
}
function sanitizeUrl(url) {
const parsed = new URL(url);
const validProtocol = !parsed.protocol || parsed.protocol === "http:" || parsed.protocol === "https:";
if (!validProtocol) {
throwOrAlert(`One Head: Native origin has invalid protocol "${parsed.protocol}" for URL in Config: ${protocolWarningString}.`);
}
parsed.pathname = "";
parsed.search = "";
parsed.hash = "";
parsed.protocol ??= "https:";
return parsed.toString().replace(/\/$/, "");
}
const memoSanitizeUrl = memoize(sanitizeUrl);
function getUrlFromConstants() {
const origin = process.env.One_ORIGIN;
if (!origin) {
throwOrAlert(`One Head: Add the handoff origin to the Config (requires rebuild). Add the Config Plugin ${protocolWarningString}, where \`origin\` is the hosted URL.`);
return "https://expo.dev";
}
if (!origin.match(/^http(s)?:\/\//)) {
console.warn(`One Head: origin "${origin}" is missing a \`https://\` protocol. ${protocolWarningString}.`);
}
return memoSanitizeUrl(origin);
}
function throwOrAlert(msg) {
console.warn(`TODO FIX: ${msg}`);
}
function getStaticUrlFromOneRouter(pathname) {
return getUrlFromConstants() + pathname;
}
export { getStaticUrlFromOneRouter };
//# sourceMappingURL=url.mjs.map