Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(docs): api crawler routes (#28614)

Charise67c2191200c
diff --git a/apps/docs/app/api/crawlers/route.ts b/apps/docs/app/api/crawlers/route.ts
index b74125beb36..51850fa26e3 100644
--- a/apps/docs/app/api/crawlers/route.ts
+++ b/apps/docs/app/api/crawlers/route.ts
@@ -30,9 +30,11 @@ export async function GET(request: Request) {
slug = maybeVersion
}
- const flattenedSections = await getFlattenedSections(lib, version)
- const sectionsWithUrl: Array<AbbrevCommonClientLibSection & { url: URL }> =
- flattenedSections!.map((section) => {
+ let section: AbbrevCommonClientLibSection
+ let sectionsWithUrl: Array<AbbrevCommonClientLibSection & { url: URL }>
+ try {
+ const flattenedSections = (await getFlattenedSections(lib, version)) ?? []
+ sectionsWithUrl = flattenedSections.map((section) => {
const url = new URL(request.url)
url.pathname = [BASE_PATH, 'reference', lib, isVersion ? version : null, section.slug]
.filter(Boolean)
@@ -43,10 +45,11 @@ export async function GET(request: Request) {
url,
}
})
- const section = flattenedSections!.find(
- (section) =>
- (section.type === 'markdown' || section.type === 'function') && section.slug === slug
- )
+ section = flattenedSections.find(
+ (section) =>
+ (section.type === 'markdown' || section.type === 'function') && section.slug === slug
+ )
+ } catch {}
if (!section) {
redirect(notFoundLink(`${lib}/${slug}`))
diff --git a/apps/docs/lib/docs.ts b/apps/docs/lib/docs.ts
index 612ce98533f..d6d84ee7630 100644
--- a/apps/docs/lib/docs.ts
+++ b/apps/docs/lib/docs.ts
@@ -12,7 +12,10 @@ import remarkMath from 'remark-math'
import codeHikeTheme from 'config/code-hike.theme.json' assert { type: 'json' }
-const DOCS_DIRECTORY = join(dirname(fileURLToPath(import.meta.url)), '..')
+// MUST be process.cwd() here, not import.meta.url, or files that are added
+// with outputFileTracingIncludes (not auto-traced) will not be found at
+// runtime.
+const DOCS_DIRECTORY = process.cwd()
export const GUIDES_DIRECTORY = join(DOCS_DIRECTORY, 'content/guides')
export const REF_DOCS_DIRECTORY = join(DOCS_DIRECTORY, 'docs/ref')
export const SPEC_DIRECTORY = join(DOCS_DIRECTORY, 'spec')