Skip to content

Commit

Permalink
fix: revalidate url
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Mar 9, 2025
1 parent ab07ba0 commit 712b362
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function ExplorerContent({
} catch (error) {
console.error(error);
// TODO: don't revalidate too often
revalidate(loader);
revalidate(await loader.getBaseUrl());
}

if (api == null) {
Expand Down
15 changes: 15 additions & 0 deletions packages/fern-docs/bundle/src/server/docs-loader.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { cleanBasePath } from "./docs-loader";

vi.mock("server-only", () => ({}));

describe("basePath", () => {
it("should clean basepath", () => {
expect(cleanBasePath(undefined)).toBe("");
expect(cleanBasePath("")).toBe("");
expect(cleanBasePath("/")).toBe("");
expect(cleanBasePath("/foo")).toBe("/foo");
expect(cleanBasePath("/foo/")).toBe("/foo");
expect(cleanBasePath("/foo/bar")).toBe("/foo/bar");
expect(cleanBasePath("/foo/bar/")).toBe("/foo/bar");
});
});
21 changes: 16 additions & 5 deletions packages/fern-docs/bundle/src/server/docs-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import {
withoutStaging,
} from "@fern-docs/utils";

import { findEndpoint } from "@/components/util/processRequestSnippetComponents";

import { findEndpoint } from "../components/util/processRequestSnippetComponents";
import { AuthState, createGetAuthState } from "./auth/getAuthState";
import { cacheSeed } from "./cache-seed";
import { generateFernColorPalette } from "./generateFernColors";
Expand Down Expand Up @@ -171,6 +170,8 @@ export interface DocsLoader {
getAuthState: (pathname?: string) => Promise<AuthState>;

getEdgeFlags: () => Promise<EdgeFlags>;

getBaseUrl: () => Promise<string>;
}

function kvSet(domain: string, key: string, value: unknown) {
Expand All @@ -187,6 +188,14 @@ const cachedGetEdgeFlags = cache(async (domain: string) => {
return await getEdgeFlags(domain);
});

export function cleanBasePath(basePath: string | undefined) {
const basepath = removeTrailingSlash(addLeadingSlash(slugjoin(basePath)));
if (basepath === "/") {
return "";
}
return basepath;
}

export const getMetadataFromResponse = async (
domain: string,
responsePromise: AsyncOrSync<DocsV2Read.LoadDocsForUrlResponse>
Expand All @@ -197,9 +206,7 @@ export const getMetadataFromResponse = async (
]);
return {
domain: response.baseUrl.domain,
basePath: removeTrailingSlash(
addLeadingSlash(slugjoin(response.baseUrl.basePath))
),
basePath: cleanBasePath(response.baseUrl.basePath),
url: docsUrlMetadata.url,
org: docsUrlMetadata.org,
isPreview: docsUrlMetadata.isPreview,
Expand Down Expand Up @@ -808,6 +815,10 @@ export const createCachedDocsLoader = async (
getFonts: () => getFonts(domain),
getAuthState,
getEdgeFlags: () => cachedGetEdgeFlags(domain),
getBaseUrl: async () => {
const m = await metadata;
return `https://${m.domain}${m.basePath}`;
},
};
};

Expand Down
3 changes: 1 addition & 2 deletions packages/fern-docs/bundle/src/server/loadWithUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { cache } from "react";
import { APIResponse, FdrAPI } from "@fern-api/fdr-sdk/client/types";
import { withoutStaging } from "@fern-docs/utils";

import { provideRegistryService } from "@/server/registry";

import { loadDocsDefinitionFromS3 } from "./loadDocsDefinitionFromS3";
import { provideRegistryService } from "./registry";

export type LoadWithUrlResponse = APIResponse<
FdrAPI.docs.v2.read.LoadDocsForUrlResponse,
Expand Down
7 changes: 2 additions & 5 deletions packages/fern-docs/bundle/src/server/revalidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import "server-only";

import { after } from "next/server";

import { DocsLoader } from "./docs-loader";

export function revalidate(loader: DocsLoader) {
export function revalidate(baseUrl: string) {
return after(async () => {
const { domain, basePath } = await loader.getMetadata();
await fetch(`https://${domain}${basePath}/api/fern-docs/revalidate`);
await fetch(`${baseUrl}/api/fern-docs/revalidate`);
});
}

1 comment on commit 712b362

@vercel
Copy link

@vercel vercel bot commented on 712b362 Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

canary.ferndocs.com – ./packages/fern-docs/bundle

docs.reka.ai
docs.airtop.ai
docs.vapi.ai
*.ferndocs.app
docs.qlty.sh
docs.vellum.ai
plantstore.dev
docs.credal.ai
docs.bytebot.ai
docs.cable.tech
docs.mercoa.com
docs.multion.ai
docs.ntropy.com
docs.nominal.io
docs.revert.dev
docs.termina.ai
help.getzep.com
docs.airweave.ai
api.labelstud.io
www.upshift.dev
docs.argolabs.ai
docs.cartesia.ai
docs.coperniq.io
docs.coactive.ai
docs.eyelevel.ai
docs.getkard.com
docs.jambonz.org
docs.paradigm.co
docs.payos.money
docs.propexo.com
docs.scoutos.com
docs.trykeet.com
docs.upshift.dev
legal.fanvue.com
developers.ada.cx
docs.agentmail.to
docs.anterior.com
docs.benchify.com
docs.darwinbio.io
docs.getanalog.ai
docs.hellodata.ai
docs.mavenagi.com
docs.syndicate.io
docs.taxcloud.com
fern.ssoready.com
prod.ferndocs.com
docs.dataglade.com
docs.flagright.com
docs.fluidstack.io
docs.paradex.trade
docs.sphinxbio.com
docs.superagent.sh
docs.usebridge.com
docs.withchima.com
r2r-docs.sciphi.ai
www.katiedanny.com
api.navipartner.com
canary.ferndocs.com
docs.brightmove.com
developers.duve.com
docs.data.aviato.co
docs.openledger.com
docs.privategpt.dev
docs.scrapybara.com
docs.withabound.com
developers.awork.com
docs.athenaintel.com
docs.getscorecard.ai
docs.givechariot.com
docs.trypinnacle.app
docs.schematichq.com
tc.docs.syndicate.io
apidocs.polytomic.com
docs-next.scoutos.com
developer.ideogram.ai
docs.axiomatic-ai.com
docs.pier-finance.com
docs.wellesley.social
developers.gappify.com
developers.beehiiv.com
docs.stage.paradigm.co
reference.flatfile.com
developers.upwardli.com
docs.impiloplatform.com
docs.aiaplatform.com.au
secure.docs.propexo.com
developer.yocobeta.co.za
docs.predictionguard.com
gusto.docs.withchima.com
documentation.sayari.com
column.docs.withchima.com
docs.conductorquantum.com
docs.joincandidhealth.com
docs.staging.paradex.trade
rippling.docs.withchima.com
angellist.docs.withchima.com
dev.documentation.sayari.com
developer.projectmanager.com
upshift.dev
docs-beta.projectmanager.com

Please sign in to comment.