Skip to content

Commit

Permalink
enable revalidating individual route
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Dec 20, 2024
1 parent 9b8fdc4 commit e132655
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/fern-docs/bundle/src/server/revalidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,26 @@ export class Revalidator implements Revalidator {
) {}

getUrl(path: string): string {
return conformTrailingSlash(urljoin(this.domain, encodeURI(path)));
if (path.startsWith("/api/fern-docs")) {
return path;
}
return `/static/${conformTrailingSlash(urljoin(this.domain, encodeURI(path)))}`;
}

async path(path: string): Promise<FernDocs.RevalidationResult> {
const url = this.getUrl(path);
const fullpath = this.getUrl(path);

console.log(`Revalidating ${url}`);
console.log(`Revalidating ${fullpath}`);
try {
await this.res.revalidate(`/static/${url}`);
return { success: true, url };
await this.res.revalidate(fullpath);
return { success: true, url: fullpath.replace(/^\/static/, "") };
} catch (error) {
console.error(`Failed to revalidate ${url}:`, error);
return { success: false, url, error: String(error) };
console.error(`Failed to revalidate ${fullpath}:`, error);
return {
success: false,
url: fullpath.replace(/^\/static/, ""),
error: String(error),
};
}
}

Expand Down

0 comments on commit e132655

Please sign in to comment.