@open-condo/miniapp-utils
Version:
A set of helper functions / components / hooks used to build new condo apps fast
71 lines (70 loc) • 2.58 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/helpers/posthog.ts
var posthog_exports = {};
__export(posthog_exports, {
generateRewrites: () => generateRewrites,
getPosthogEndpoint: () => getPosthogEndpoint
});
module.exports = __toCommonJS(posthog_exports);
var POSTHOG_CLOUD_HOST_BASE = "i.posthog.com";
var POSTHOG_CLOUD_HOST_MATCHER = new RegExp(`^(\\w+)\\.${POSTHOG_CLOUD_HOST_BASE.replaceAll(".", "\\.")}$`);
function getPosthogEndpoint(posthogDomain, requestedPath) {
const posthogURL = new URL(posthogDomain);
const cloudMatch = posthogURL.host.match(POSTHOG_CLOUD_HOST_MATCHER);
if (cloudMatch && cloudMatch.length > 1) {
const region = cloudMatch[1];
if (requestedPath.length && requestedPath[0] === "static") {
posthogURL.host = `${region}-assets.${POSTHOG_CLOUD_HOST_BASE}`;
posthogURL.pathname = requestedPath.slice(1).join("/");
return posthogURL.toString();
}
}
posthogURL.pathname = requestedPath.join("/");
return posthogURL.toString();
}
function generateRewrites(postHogDomain, routeEndpoint) {
const url = new URL(postHogDomain);
const match = url.host.match(POSTHOG_CLOUD_HOST_MATCHER);
if (match && match.length > 1) {
const region = match[1];
return [
{
source: `${routeEndpoint}/static/:path*`,
destination: `https://${region}-assets.${POSTHOG_CLOUD_HOST_BASE}/static/:path*`
},
{
source: `${routeEndpoint}/:path*`,
destination: `https://${region}.${POSTHOG_CLOUD_HOST_BASE}/:path*`
}
];
}
return [
{
source: `${routeEndpoint}/:path*`,
destination: `${postHogDomain}/:path*`
}
];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
generateRewrites,
getPosthogEndpoint
});
//# sourceMappingURL=posthog.js.map