@@ -21,11 +21,14 @@ interface SchemaPropertyDetails {
2121 * Gets the base URL for API requests, adjusting for GitHub Pages in production
2222 */
2323const getApiBase = ( ) => {
24- // In production (GitHub Pages), use static JSON files in the /api directory
25- if ( process . env . NODE_ENV === "production" ) {
24+ // Determine if this is a GitHub Pages specific build
25+ const isGithubPagesBuild = process . env . GITHUB_PAGES_BUILD === 'true' ;
26+
27+ // Use GitHub Pages path ONLY when specifically building for GitHub Pages
28+ if ( isGithubPagesBuild ) {
2629 return "/JSON_Schema_Validator/api" ;
2730 }
28- // In development, use the dynamic API routes
31+ // In all other cases ( development, Vercel, CI tests, standard prod builds)
2932 return "/api" ;
3033} ;
3134
@@ -63,12 +66,18 @@ export async function getSchemaByName(
6366 . replace ( / \. j s o n $ / , "" )
6467 . replace ( / [ ^ \w - ] / g, "" ) ;
6568
66- // In development, fetch directly from public folder
67- // In production, fetch the static JSON generated by the build script
68- const url =
69- process . env . NODE_ENV === "production"
70- ? `${ getApiBase ( ) } /schemas/${ safeSchemaName } .json` // Prod URL remains the same (fetches from public/api/schemas)
71- : `/schemas/v1/${ safeSchemaName } .json` ; // Changed dev URL (fetches from public/schemas/v1)
69+ // Determine the correct URL based on environment
70+ const isGithubPagesBuild = process . env . GITHUB_PAGES_BUILD === 'true' ;
71+ const isProduction = process . env . NODE_ENV === 'production' ;
72+
73+ // Use static paths for GitHub Pages build, dynamic API otherwise
74+ const url = isGithubPagesBuild
75+ ? `${ getApiBase ( ) } /schemas/${ safeSchemaName } .json` // /JSON_Schema_Validator/api/schemas/...json
76+ : isProduction
77+ ? `/api/get-schema/${ safeSchemaName } ` // Use API route in regular production (Vercel)
78+ : `/schemas/v1/${ safeSchemaName } .json` ; // Dev fetches directly from public/schemas/v1
79+
80+ console . log ( `[getSchemaByName] Fetching schema from URL: ${ url } ` ) ; // Debug logging
7281
7382 try {
7483 const response = await fetch ( url ) ;
@@ -137,8 +146,14 @@ function generateClientSideMarkdown(schema: Record<string, unknown>): string {
137146export async function generateSchemaDocumentation (
138147 schema : Record < string , unknown > ,
139148) : Promise < { markdown : string } > {
140- // In production, generate markdown on the client side
141- if ( process . env . NODE_ENV === "production" ) {
149+ // Generate on client side if building for GitHub Pages or in production (Vercel)
150+ const isClientSideGeneration =
151+ process . env . GITHUB_PAGES_BUILD === 'true' || process . env . NODE_ENV === "production" ;
152+
153+ if ( isClientSideGeneration ) {
154+ console . log (
155+ "Generating schema documentation on the client side (Prod/GitHub Pages)" ,
156+ ) ;
142157 try {
143158 return { markdown : generateClientSideMarkdown ( schema ) } ;
144159 } catch ( error ) {
@@ -153,6 +168,7 @@ export async function generateSchemaDocumentation(
153168 }
154169
155170 // In development, try the API endpoint first, fallback to client-side if unavailable
171+ console . log ( "Attempting to generate schema documentation via API (Dev)" ) ;
156172 try {
157173 // Use the absolute path to ensure the request works correctly
158174 const url = "/api/generate-schema-doc" ;
0 commit comments