@@ -16,13 +16,27 @@ import logger from './universal/utils/logger';
1616import omit from 'lodash/omit' ;
1717
1818const appConfig = require ( '__APP_CONFIG__' ) ;
19+ const previewPages = require ( '__V_PREVIEW_PAGES__' ) ;
20+
21+ function getPreview ( output ) {
22+ const { layouts = { } } = previewPages ?. default || { } ;
23+ let PreviewFile = Preview ;
24+
25+ console . log ( 'layouts:' , layouts ) ;
26+ if ( layouts . default ) {
27+ PreviewFile = layouts . default ;
28+ }
29+
30+ return PreviewFile ( output ) ;
31+ }
1932
2033const render = async ( req , res ) => {
2134 const isWithoutStateValue = isWithoutState ( req . query ) ;
2235 const pathParts = xss ( req . path )
2336 . split ( '/' )
2437 . filter ( part => part ) ;
2538 const componentPath = `/${ pathParts . join ( '/' ) } ` ;
39+ const isPreviewValue = isPreview ( req . query ) ;
2640
2741 const routeInfo = matchUrlInRouteConfigs ( componentPath ) ;
2842
@@ -38,7 +52,8 @@ const render = async (req, res) => {
3852 . replace ( '//' , '/' ) ,
3953 userAgent : Buffer . from ( req . headers [ 'user-agent' ] || [ ] , 'utf-8' ) . toString ( 'base64' ) ,
4054 headers : JSON . parse ( xss ( JSON . stringify ( req . headers ) ) ) ,
41- isWithoutState : isWithoutStateValue
55+ isWithoutState : isWithoutStateValue ,
56+ isPreview : isPreviewValue
4257 } ;
4358
4459 const component = new Component ( routeInfo . path ) ;
@@ -82,7 +97,8 @@ const render = async (req, res) => {
8297 const voltranEnv = appConfig . voltranEnv || 'local' ;
8398
8499 if ( voltranEnv !== 'prod' && isPreviewQuery ) {
85- res . status ( statusCode ) . html ( Preview ( [ fullHtml ] . join ( '\n' ) ) ) ;
100+ const response = getPreview ( [ fullHtml ] . join ( '\n' ) ) ;
101+ res . status ( statusCode ) . html ( response ) ;
86102 } else {
87103 res
88104 . status ( HTTP_STATUS_CODES . INTERNAL_SERVER_ERROR )
0 commit comments