one
Version:
One is a new React Framework that makes Vite serve both native and web.
50 lines (49 loc) • 1.8 kB
JavaScript
var protocolWarningString = `{ plugins: [["router", { origin: "...<URL>..." }]] }`;
function memoize(fn) {
var cache = {};
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var key = JSON.stringify(args);
if (cache[key]) {
return cache[key];
}
var result = fn(...args);
cache[key] = result;
return result;
};
}
function sanitizeUrl(url) {
var _parsed, _protocol;
var parsed = new URL(url);
var 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 = "";
(_protocol = (_parsed = parsed).protocol) !== null && _protocol !== void 0 ? _protocol : _parsed.protocol = "https:";
return parsed.toString().replace(/\/$/, "");
}
var memoSanitizeUrl = memoize(sanitizeUrl);
function getUrlFromConstants() {
var 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.native.js.map