@@ -26,10 +26,9 @@ const logger = pino({
2626 options : {
2727 colorize : true ,
2828 translateTime : 'SYS:standard' ,
29- destination : `${ __dirname } /pino-logger.log` ,
3029 } ,
3130 } ,
32- level : 'info' ,
31+ level : process . env . LOG_LEVEL || 'info' ,
3332} ) ;
3433
3534const logRequestTimer = ( req : Request ) => {
@@ -51,7 +50,7 @@ const fetchMetaData = async (namespace: string, publishName?: string) => {
5150 url = `${ baseURL } /api/workspace/v1/published/${ namespace } /${ publishName } ` ;
5251 }
5352
54- logger . info ( `Fetching meta data from ${ url } ` ) ;
53+ logger . debug ( `Fetching meta data from ${ url } ` ) ;
5554 try {
5655 const response = await fetch ( url , {
5756 verbose : true ,
@@ -63,11 +62,11 @@ const fetchMetaData = async (namespace: string, publishName?: string) => {
6362
6463 const data = await response . json ( ) ;
6564
66- logger . info ( `Fetched meta data from ${ url } : ${ JSON . stringify ( data ) } ` ) ;
65+ logger . debug ( `Fetched meta data from ${ url } : ${ JSON . stringify ( data ) } ` ) ;
6766
6867 return data ;
6968 } catch ( error ) {
70- logger . error ( `Error fetching meta data ${ error } ` ) ;
69+ logger . error ( `Failed to fetch meta data from ${ url } : ${ error } ` ) ;
7170 return null ;
7271 }
7372} ;
@@ -130,31 +129,36 @@ const createServer = async (req: Request) => {
130129 }
131130
132131 let metaData ;
132+ let redirectAttempted = false ;
133133
134134 try {
135135 const data = await fetchMetaData ( namespace , publishName ) ;
136136
137137 if ( publishName ) {
138- if ( data . code === 0 ) {
138+ if ( data && data . code === 0 ) {
139139 metaData = data . data ;
140140 } else {
141- logger . error ( `Error fetching meta data: ${ JSON . stringify ( data ) } ` ) ;
141+ logger . error (
142+ `Publish view lookup failed for namespace="${ namespace } " publishName="${ publishName } " response=${ JSON . stringify ( data ) } `
143+ ) ;
142144 }
143145 } else {
144-
145146 const publishInfo = data ?. data ?. info ;
146147
147- if ( publishInfo ) {
148+ if ( publishInfo ?. namespace && publishInfo ?. publish_name ) {
148149 const newURL = `/${ encodeURIComponent ( publishInfo . namespace ) } /${ encodeURIComponent ( publishInfo . publish_name ) } ` ;
149150
150151 logger . info ( `Redirecting to default page in: ${ JSON . stringify ( publishInfo ) } ` ) ;
152+ redirectAttempted = true ;
151153 timer ( ) ;
152154 return new Response ( null , {
153155 status : 302 ,
154156 headers : {
155157 Location : newURL ,
156158 } ,
157159 } ) ;
160+ } else {
161+ logger . warn ( `Namespace "${ namespace } " has no default publish page. response=${ JSON . stringify ( data ) } ` ) ;
158162 }
159163 }
160164 } catch ( error ) {
@@ -219,6 +223,12 @@ const createServer = async (req: Request) => {
219223 logger . error ( `Error injecting meta data: ${ error } ` ) ;
220224 }
221225
226+ if ( ! metaData ) {
227+ logger . warn (
228+ `Serving fallback landing page for namespace="${ namespace } " publishName="${ publishName ?? '' } ". redirectAttempted=${ redirectAttempted } `
229+ ) ;
230+ }
231+
222232 $ ( 'title' ) . text ( title ) ;
223233 $ ( 'link[rel="icon"]' ) . attr ( 'href' , favicon ) ;
224234 $ ( 'link[rel="canonical"]' ) . attr ( 'href' , url ) ;
0 commit comments