@@ -361,41 +361,41 @@ export class HelixServer extends BaseServer {
361361 const contentFilePath = path . join ( contentDir , ctx . path ) ;
362362 if ( ! path . relative ( contentDir , contentFilePath ) . startsWith ( '..' ) ) {
363363 try {
364- const contentStat = await lstat ( contentFilePath ) ;
365- if ( contentStat . isFile ( ) ) {
366- if ( contentFilePath . endsWith ( '.html' ) ) {
367- let htmlContent = await readFile ( contentFilePath , 'utf-8' ) ;
368- // aem-content files are plain HTML (body only, no <head>)
369- // wrap with a full document and inject local head.html
370- if ( ! htmlContent . includes ( '<head>' ) ) {
371- await this . _project . headHtml . update ( ) ;
372- const headHtml = this . _project . headHtml . localHtml || '' ;
373- htmlContent = `<html><head>${ headHtml } </head>${ htmlContent } </html>` ;
374- } else {
375- await this . _project . headHtml . setCookie ( req . headers . cookie ) ;
376- htmlContent = await this . _project . headHtml . replace ( htmlContent ) ;
377- }
378- if ( liveReload ) {
379- htmlContent = utils . injectLiveReloadScript ( htmlContent , this ) ;
380- liveReload . registerFile ( ctx . requestId , contentFilePath ) ;
381- }
382- res . set ( {
383- 'content-type' : 'text/html; charset=utf-8' ,
384- 'access-control-allow-origin' : '*' ,
385- } ) ;
386- res . send ( htmlContent ) ;
364+ if ( contentFilePath . endsWith ( '.html' ) ) {
365+ // readFile throws EISDIR for directories and ENOENT for missing files
366+ let htmlContent = await readFile ( contentFilePath , 'utf-8' ) ;
367+ // aem-content files are plain HTML (body only, no <head>)
368+ // wrap with a full document and inject local head.html
369+ if ( ! htmlContent . includes ( '<head>' ) ) {
370+ await this . _project . headHtml . update ( ) ;
371+ const headHtml = this . _project . headHtml . localHtml || '' ;
372+ htmlContent = `<html><head>${ headHtml } </head>${ htmlContent } </html>` ;
387373 } else {
388- await sendFile ( contentFilePath , {
389- dotfiles : 'allow' ,
390- headers : { 'access-control-allow-origin' : '*' } ,
391- } ) ;
392- if ( liveReload ) {
393- liveReload . registerFile ( ctx . requestId , contentFilePath ) ;
394- }
374+ await this . _project . headHtml . setCookie ( req . headers . cookie ) ;
375+ htmlContent = await this . _project . headHtml . replace ( htmlContent ) ;
395376 }
377+ if ( liveReload ) {
378+ htmlContent = utils . injectLiveReloadScript ( htmlContent , this ) ;
379+ liveReload . registerFile ( ctx . requestId , contentFilePath ) ;
380+ }
381+ res . set ( {
382+ 'content-type' : 'text/html; charset=utf-8' ,
383+ 'access-control-allow-origin' : '*' ,
384+ } ) ;
385+ res . send ( htmlContent ) ;
396386 log . debug ( `${ pfx } served from aem-content/: ${ ctx . path } ` ) ;
397387 return ;
398388 }
389+ // sendFile throws EISDIR for directories and ENOENT for missing files
390+ await sendFile ( contentFilePath , {
391+ dotfiles : 'allow' ,
392+ headers : { 'access-control-allow-origin' : '*' } ,
393+ } ) ;
394+ if ( liveReload ) {
395+ liveReload . registerFile ( ctx . requestId , contentFilePath ) ;
396+ }
397+ log . debug ( `${ pfx } served from aem-content/: ${ ctx . path } ` ) ;
398+ return ;
399399 } catch ( e ) {
400400 log . debug ( `${ pfx } aem-content/ miss for ${ ctx . path } : ${ e . code } ` ) ;
401401 }
0 commit comments