1+ /* eslint-disable no-return-await */ 
12import  React  from  'react' ; 
23import  {  replaceValues  }  from  '../utils/propsUtil' ; 
34import  {  renderPage  }  from  './renderPage' ; 
45import  {  log  }  from  './helpers' ; 
56import  {  Error  }  from  '../components/Error' ; 
67
7- function  paramfn ( sq ,  req ,  res ,  next ,  options )  { 
8+ async   function  paramfn ( sq ,  req ,  res ,  next ,  options )  { 
89 // eslint-disable-next-line no-restricted-syntax 
910 for  ( const  param  of  sq )  { 
1011 switch  ( param . type )  { 
@@ -29,7 +30,8 @@ function paramfn(sq, req, res, next, options) {
2930 // res.end(); 
3031 break ; 
3132 case  'render' :
32-  res . send ( renderPage ( param . content ,  {  req,  res } ,  options ) ) ; 
33+  // eslint-disable-next-line no-await-in-loop 
34+  res . send ( await  renderPage ( param . content ,  {  req,  res } ,  options ) ) ; 
3335 break ; 
3436 case  'send-file' :
3537 res . sendFile ( param . content . path ,  param . content . options ,  ( err )  =>  { 
@@ -52,8 +54,11 @@ export function generateRoute(router, props, options = {}) {
5254 async  ( req ,  res ,  next )  =>  { 
5355 if  ( props . handler ) 
5456 try  { 
55-  await  props . handler ( req ,  res ,  next ,  ( Component )  => 
56-  renderPage ( Component ,  {  req,  res } ,  options ) 
57+  await  props . handler ( 
58+  req , 
59+  res , 
60+  next , 
61+  async  ( Component )  =>  await  renderPage ( Component ,  {  req,  res } ,  options ) 
5762 ) ; 
5863 }  catch  ( error )  { 
5964 const  msg  =  `Error in the handler passed to this route <${ props . method [ 0 ] . toUpperCase ( ) } ${ props . method . slice (  
@@ -65,14 +70,16 @@ export function generateRoute(router, props, options = {}) {
6570 res . writableEnded  =  true ; 
6671 res . statusCode  =  500 ; 
6772 if  ( props . method  ===  'get' )  { 
68-  res . end ( renderPage ( ( )  =>  < Error  msg = { msg }  error = { error }  /> ,  {  req,  res } ,  options ) ) ; 
73+  res . end ( 
74+  await  renderPage ( ( )  =>  < Error  msg = { msg }  error = { error }  /> ,  {  req,  res } ,  options ) 
75+  ) ; 
6976 }  else  { 
7077 res . end ( msg ) ; 
7178 } 
7279 } 
7380
7481 if  ( props . paramsSeq  &&  ! res . writableEnded )  { 
75-  paramfn ( props . paramsSeq ,  req ,  res ,  next ,  options ) ; 
82+  await   paramfn ( props . paramsSeq ,  req ,  res ,  next ,  options ) ; 
7683 } 
7784 } , 
7885 ] 
0 commit comments