Skip to content

Commit 380a3d7

Browse files
authored
chore: fix is preview url (#3287)
1 parent 734b5ae commit 380a3d7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

packages/commons/docs-utils/src/__test__/isPreviewDomain.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { extractOrgFromPreview, isPreviewDomain } from "../isPreviewUrl";
22

33
describe("isPreviewDomain", () => {
4-
it("should return true for valid preview domains", () => {
4+
it("should return true for preview domains with truncated UUIDs", () => {
55
const validDomains = [
6-
"fern-12345678-1234-1234-1234-123456789012.docs.buildwithfern.com",
7-
"acme-abcdef01-2345-6789-abcd-ef0123456789.docs.buildwithfern.com",
6+
"payabli-preview-fad23292-87bd-4eec-bf26-.docs.buildwithfern.com",
87
];
98

109
validDomains.forEach((domain) => {

packages/commons/docs-utils/src/isPreviewUrl.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
export function isPreviewDomain(domain: string): boolean {
2-
const uuidRegex =
3-
"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";
4-
return new RegExp(`^.*?${uuidRegex}\\.docs\\.buildwithfern\\.com$`).test(
5-
domain
6-
);
2+
// Accepts org-preview-<uuid-or-truncated-uuid>.docs.buildwithfern.com
3+
// The uuid part can be truncated, so allow trailing dash and partial uuid
4+
const previewUuidPattern = /preview-[0-9a-f-]+/i;
5+
const hasPattern = previewUuidPattern.test(domain);
6+
// Add logs for debugging
7+
if (typeof console !== "undefined" && typeof console.log === "function") {
8+
console.log(`[isPreviewDomain] Checking domain: ${domain}`);
9+
console.log(`[isPreviewDomain] Pattern: ${previewUuidPattern}`);
10+
console.log(`[isPreviewDomain] Match result: ${hasPattern}`);
11+
}
12+
return hasPattern;
713
}
814

915
export function extractOrgFromPreview(domain: string): string | undefined {

0 commit comments

Comments
 (0)